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.c75
1 files changed, 45 insertions, 30 deletions
diff --git a/src/3rdparty/freetype/src/bzip2/ftbzip2.c b/src/3rdparty/freetype/src/bzip2/ftbzip2.c
index 411c5d263b..ad342bd011 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-2020 by
+ * Copyright (C) 2010-2023 by
* Joel Klinghed.
*
* based on `src/gzip/ftgzip.c'
@@ -57,28 +57,34 @@
/* 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,
- int items,
- int size )
+ ft_bzip2_alloc( void* memory_, /* FT_Memory */
+ int items,
+ int size )
{
+ FT_Memory memory = (FT_Memory)memory_;
+
FT_ULong sz = (FT_ULong)size * (FT_ULong)items;
FT_Error error;
FT_Pointer p = NULL;
- (void)FT_ALLOC( p, sz );
+ FT_MEM_QALLOC( p, sz );
return p;
}
static void
- ft_bzip2_free( FT_Memory memory,
- void* address )
+ ft_bzip2_free( void* memory_, /* FT_Memory */
+ void* address )
{
+ FT_Memory memory = (FT_Memory)memory_;
+
+
FT_MEM_FREE( address );
}
@@ -102,10 +108,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;
@@ -153,6 +160,7 @@
zip->limit = zip->buffer + FT_BZIP2_BUFFER_SIZE;
zip->cursor = zip->limit;
zip->pos = 0;
+ zip->reset = 0;
/* check .bz2 header */
{
@@ -167,8 +175,8 @@
}
/* initialize bzlib */
- bzstream->bzalloc = (alloc_func)ft_bzip2_alloc;
- bzstream->bzfree = (free_func) ft_bzip2_free;
+ bzstream->bzalloc = ft_bzip2_alloc;
+ bzstream->bzfree = ft_bzip2_free;
bzstream->opaque = zip->memory;
bzstream->avail_in = 0;
@@ -228,6 +236,7 @@
zip->limit = zip->buffer + FT_BZIP2_BUFFER_SIZE;
zip->cursor = zip->limit;
zip->pos = 0;
+ zip->reset = 0;
BZ2_bzDecompressInit( bzstream, 0, 0 );
}
@@ -302,18 +311,23 @@
err = BZ2_bzDecompress( bzstream );
- if ( err == BZ_STREAM_END )
+ if ( err != BZ_OK )
{
- zip->limit = (FT_Byte*)bzstream->next_out;
- if ( zip->limit == zip->cursor )
- error = FT_THROW( Invalid_Stream_Operation );
- break;
- }
- else 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;
+ }
}
}
@@ -327,12 +341,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;
@@ -362,9 +377,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 )
@@ -494,7 +509,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;