summaryrefslogtreecommitdiffstats
path: root/src/3rdparty/freetype/src/lzw
diff options
context:
space:
mode:
Diffstat (limited to 'src/3rdparty/freetype/src/lzw')
-rw-r--r--src/3rdparty/freetype/src/lzw/ftlzw.c35
-rw-r--r--src/3rdparty/freetype/src/lzw/ftzopen.c26
-rw-r--r--src/3rdparty/freetype/src/lzw/ftzopen.h2
3 files changed, 43 insertions, 20 deletions
diff --git a/src/3rdparty/freetype/src/lzw/ftlzw.c b/src/3rdparty/freetype/src/lzw/ftlzw.c
index 6e57dedb97..e1b3564a5f 100644
--- a/src/3rdparty/freetype/src/lzw/ftlzw.c
+++ b/src/3rdparty/freetype/src/lzw/ftlzw.c
@@ -8,7 +8,7 @@
/* be used to parse compressed PCF fonts, as found with many X11 server */
/* distributions. */
/* */
-/* Copyright 2004, 2005, 2006, 2009, 2010 by */
+/* Copyright 2004-2006, 2009, 2010, 2012-2014 by */
/* Albert Chin-A-Young. */
/* */
/* Based on code in src/gzip/ftgzip.c, Copyright 2004 by */
@@ -34,6 +34,7 @@
#undef __FTERRORS_H__
+#undef FT_ERR_PREFIX
#define FT_ERR_PREFIX LZW_Err_
#define FT_ERR_BASE FT_Mod_Err_LZW
@@ -44,7 +45,7 @@
#ifdef FT_CONFIG_OPTION_PIC
#error "lzw code does not support PIC yet"
-#endif
+#endif
#include "ftzopen.h"
@@ -95,9 +96,9 @@
goto Exit;
/* head[0] && head[1] are the magic numbers */
- if ( head[0] != 0x1f ||
- head[1] != 0x9d )
- error = LZW_Err_Invalid_File_Format;
+ if ( head[0] != 0x1F ||
+ head[1] != 0x9D )
+ error = FT_THROW( Invalid_File_Format );
Exit:
return error;
@@ -110,7 +111,7 @@
FT_Stream source )
{
FT_LzwState lzw = &zip->lzw;
- FT_Error error = LZW_Err_Ok;
+ FT_Error error;
zip->stream = stream;
@@ -171,7 +172,7 @@
{
FT_LzwState lzw = &zip->lzw;
FT_ULong count;
- FT_Error error = 0;
+ FT_Error error = FT_Err_Ok;
zip->cursor = zip->buffer;
@@ -181,7 +182,7 @@
zip->limit = zip->cursor + count;
if ( count == 0 )
- error = LZW_Err_Invalid_Stream_Operation;
+ error = FT_THROW( Invalid_Stream_Operation );
return error;
}
@@ -192,7 +193,7 @@
ft_lzw_file_skip_output( FT_LZWFile zip,
FT_ULong count )
{
- FT_Error error = LZW_Err_Ok;
+ FT_Error error = FT_Err_Ok;
/* first, we skip what we can from the output buffer */
@@ -223,7 +224,7 @@
if ( numread < delta )
{
/* not enough bytes */
- error = LZW_Err_Invalid_Stream_Operation;
+ error = FT_THROW( Invalid_Stream_Operation );
break;
}
@@ -348,10 +349,18 @@
FT_Stream source )
{
FT_Error error;
- FT_Memory memory = source->memory;
- FT_LZWFile zip;
+ FT_Memory memory;
+ FT_LZWFile zip = NULL;
+ if ( !stream || !source )
+ {
+ error = FT_THROW( Invalid_Stream_Handle );
+ goto Exit;
+ }
+
+ memory = source->memory;
+
/*
* Check the header right now; this prevents allocation of a huge
* LZWFile object (400 KByte of heap memory) if not necessary.
@@ -402,7 +411,7 @@
FT_UNUSED( stream );
FT_UNUSED( source );
- return LZW_Err_Unimplemented_Feature;
+ return FT_THROW( Unimplemented_Feature );
}
diff --git a/src/3rdparty/freetype/src/lzw/ftzopen.c b/src/3rdparty/freetype/src/lzw/ftzopen.c
index 8bc65c8f57..d7a64576ba 100644
--- a/src/3rdparty/freetype/src/lzw/ftzopen.c
+++ b/src/3rdparty/freetype/src/lzw/ftzopen.c
@@ -8,7 +8,7 @@
/* be used to parse compressed PCF fonts, as found with many X11 server */
/* distributions. */
/* */
-/* Copyright 2005, 2006, 2007, 2009 by David Turner. */
+/* Copyright 2005-2007, 2009, 2011 by David Turner. */
/* */
/* This file is part of the FreeType project, and may only be used, */
/* modified, and distributed under the terms of the FreeType project */
@@ -124,6 +124,15 @@
old_size = 0;
}
+ /* requirement of the character stack larger than 1<<LZW_MAX_BITS */
+ /* implies bug in the decompression code */
+ if ( new_size > ( 1 << LZW_MAX_BITS ) )
+ {
+ new_size = 1 << LZW_MAX_BITS;
+ if ( new_size == old_size )
+ return -1;
+ }
+
if ( FT_RENEW_ARRAY( state->stack, old_size, new_size ) )
return -1;
@@ -279,7 +288,7 @@
: state->max_free + 1;
c = ft_lzwstate_get_code( state );
- if ( c < 0 )
+ if ( c < 0 || c > 255 )
goto Eof;
old_code = old_char = (FT_UInt)c;
@@ -312,11 +321,12 @@
/* why not LZW_FIRST-256 ? */
state->free_ent = ( LZW_FIRST - 1 ) - 256;
state->buf_clear = 1;
- c = ft_lzwstate_get_code( state );
- if ( c < 0 )
- goto Eof;
- code = (FT_UInt)c;
+ /* not quite right, but at least more predictable */
+ old_code = 0;
+ old_char = 0;
+
+ goto NextCode;
}
in_code = code; /* save code for later */
@@ -326,6 +336,10 @@
/* special case for KwKwKwK */
if ( code - 256U >= state->free_ent )
{
+ /* corrupted LZW stream */
+ if ( code - 256U > state->free_ent )
+ goto Eof;
+
FTLZW_STACK_PUSH( old_char );
code = old_code;
}
diff --git a/src/3rdparty/freetype/src/lzw/ftzopen.h b/src/3rdparty/freetype/src/lzw/ftzopen.h
index f7d2936be2..cdc8fd7c1a 100644
--- a/src/3rdparty/freetype/src/lzw/ftzopen.h
+++ b/src/3rdparty/freetype/src/lzw/ftzopen.h
@@ -41,7 +41,7 @@
#define LZW_CLEAR 256
#define LZW_FIRST 257
-#define LZW_BIT_MASK 0x1f
+#define LZW_BIT_MASK 0x1F
#define LZW_BLOCK_MASK 0x80
#define LZW_MASK( n ) ( ( 1U << (n) ) - 1U )