summaryrefslogtreecommitdiffstats
path: root/src/3rdparty/freetype/src/bzip2/ftbzip2.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/3rdparty/freetype/src/bzip2/ftbzip2.c')
-rw-r--r--src/3rdparty/freetype/src/bzip2/ftbzip2.c69
1 files changed, 39 insertions, 30 deletions
diff --git a/src/3rdparty/freetype/src/bzip2/ftbzip2.c b/src/3rdparty/freetype/src/bzip2/ftbzip2.c
index 1fda59b60c..ab2da7e62b 100644
--- a/src/3rdparty/freetype/src/bzip2/ftbzip2.c
+++ b/src/3rdparty/freetype/src/bzip2/ftbzip2.c
@@ -8,7 +8,7 @@
* parse compressed PCF fonts, as found with many X11 server
* distributions.
*
- * Copyright (C) 2010-2019 by
+ * Copyright (C) 2010-2022 by
* Joel Klinghed.
*
* based on `src/gzip/ftgzip.c'
@@ -22,15 +22,14 @@
*/
-#include <ft2build.h>
-#include FT_INTERNAL_MEMORY_H
-#include FT_INTERNAL_STREAM_H
-#include FT_INTERNAL_DEBUG_H
-#include FT_BZIP2_H
+#include <freetype/internal/ftmemory.h>
+#include <freetype/internal/ftstream.h>
+#include <freetype/internal/ftdebug.h>
+#include <freetype/ftbzip2.h>
#include FT_CONFIG_STANDARD_LIBRARY_H
-#include FT_MODULE_ERRORS_H
+#include <freetype/ftmoderr.h>
#undef FTERRORS_H_
@@ -38,7 +37,7 @@
#define FT_ERR_PREFIX Bzip2_Err_
#define FT_ERR_BASE FT_Mod_Err_Bzip2
-#include FT_ERRORS_H
+#include <freetype/fterrors.h>
#ifdef FT_CONFIG_OPTION_USE_BZIP2
@@ -58,8 +57,9 @@
/* it is better to use FreeType memory routines instead of raw
'malloc/free' */
- typedef void *(* alloc_func)(void*, int, int);
- typedef void (* free_func)(void*, void*);
+ typedef void* (*alloc_func)( void*, int, int );
+ typedef void (*free_func) ( void*, void* );
+
static void*
ft_bzip2_alloc( FT_Memory memory,
@@ -71,7 +71,7 @@
FT_Pointer p = NULL;
- (void)FT_ALLOC( p, sz );
+ FT_MEM_QALLOC( p, sz );
return p;
}
@@ -103,10 +103,11 @@
FT_Byte input[FT_BZIP2_BUFFER_SIZE]; /* input read buffer */
- FT_Byte buffer[FT_BZIP2_BUFFER_SIZE]; /* output buffer */
- FT_ULong pos; /* position in output */
+ FT_Byte buffer[FT_BZIP2_BUFFER_SIZE]; /* output buffer */
+ FT_ULong pos; /* position in output */
FT_Byte* cursor;
FT_Byte* limit;
+ FT_Bool reset; /* reset before next read */
} FT_BZip2FileRec, *FT_BZip2File;
@@ -154,6 +155,7 @@
zip->limit = zip->buffer + FT_BZIP2_BUFFER_SIZE;
zip->cursor = zip->limit;
zip->pos = 0;
+ zip->reset = 0;
/* check .bz2 header */
{
@@ -229,6 +231,7 @@
zip->limit = zip->buffer + FT_BZIP2_BUFFER_SIZE;
zip->cursor = zip->limit;
zip->pos = 0;
+ zip->reset = 0;
BZ2_bzDecompressInit( bzstream, 0, 0 );
}
@@ -303,18 +306,23 @@
err = BZ2_bzDecompress( bzstream );
- if ( err == BZ_STREAM_END )
- {
- zip->limit = (FT_Byte*)bzstream->next_out;
- if ( zip->limit == zip->cursor )
- error = FT_THROW( Invalid_Stream_Operation );
- break;
- }
- else if ( err != BZ_OK )
+ if ( err != BZ_OK )
{
- zip->limit = zip->cursor;
- error = FT_THROW( Invalid_Stream_Operation );
- break;
+ zip->reset = 1;
+
+ if ( err == BZ_STREAM_END )
+ {
+ zip->limit = (FT_Byte*)bzstream->next_out;
+ if ( zip->limit == zip->cursor )
+ error = FT_THROW( Invalid_Stream_Operation );
+ break;
+ }
+ else
+ {
+ zip->limit = zip->cursor;
+ error = FT_THROW( Invalid_Stream_Operation );
+ break;
+ }
}
}
@@ -328,12 +336,13 @@
FT_ULong count )
{
FT_Error error = FT_Err_Ok;
- FT_ULong delta;
for (;;)
{
- delta = (FT_ULong)( zip->limit - zip->cursor );
+ FT_ULong delta = (FT_ULong)( zip->limit - zip->cursor );
+
+
if ( delta >= count )
delta = count;
@@ -363,9 +372,9 @@
FT_Error error;
- /* Reset inflate stream if we're seeking backwards. */
- /* Yes, that is not too efficient, but it saves memory :-) */
- if ( pos < zip->pos )
+ /* Reset inflate stream if seeking backwards or bzip reported an error. */
+ /* Yes, that is not too efficient, but it saves memory :-) */
+ if ( pos < zip->pos || zip->reset )
{
error = ft_bzip2_file_reset( zip );
if ( error )
@@ -495,7 +504,7 @@
stream->size = 0x7FFFFFFFL; /* don't know the real size! */
stream->pos = 0;
- stream->base = 0;
+ stream->base = NULL;
stream->read = ft_bzip2_stream_io;
stream->close = ft_bzip2_stream_close;