summaryrefslogtreecommitdiffstats
path: root/src/3rdparty/freetype/src/base/ftstream.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/3rdparty/freetype/src/base/ftstream.c')
-rw-r--r--src/3rdparty/freetype/src/base/ftstream.c142
1 files changed, 79 insertions, 63 deletions
diff --git a/src/3rdparty/freetype/src/base/ftstream.c b/src/3rdparty/freetype/src/base/ftstream.c
index b638599dbc..759fd8fc07 100644
--- a/src/3rdparty/freetype/src/base/ftstream.c
+++ b/src/3rdparty/freetype/src/base/ftstream.c
@@ -4,7 +4,7 @@
/* */
/* I/O stream support (body). */
/* */
-/* Copyright 2000-2001, 2002, 2004, 2005, 2006, 2008, 2009 by */
+/* Copyright 2000-2002, 2004-2006, 2008-2011, 2013 by */
/* David Turner, Robert Wilhelm, and Werner Lemberg. */
/* */
/* This file is part of the FreeType project, and may only be used, */
@@ -68,7 +68,7 @@
" invalid i/o; pos = 0x%lx, size = 0x%lx\n",
pos, stream->size ));
- error = FT_Err_Invalid_Stream_Operation;
+ error = FT_THROW( Invalid_Stream_Operation );
}
}
/* note that seeking to the first position after the file is valid */
@@ -78,7 +78,7 @@
" invalid i/o; pos = 0x%lx, size = 0x%lx\n",
pos, stream->size ));
- error = FT_Err_Invalid_Stream_Operation;
+ error = FT_THROW( Invalid_Stream_Operation );
}
if ( !error )
@@ -93,7 +93,7 @@
FT_Long distance )
{
if ( distance < 0 )
- return FT_Err_Invalid_Stream_Operation;
+ return FT_THROW( Invalid_Stream_Operation );
return FT_Stream_Seek( stream, (FT_ULong)( stream->pos + distance ) );
}
@@ -131,7 +131,7 @@
" invalid i/o; pos = 0x%lx, size = 0x%lx\n",
pos, stream->size ));
- return FT_Err_Invalid_Stream_Operation;
+ return FT_THROW( Invalid_Stream_Operation );
}
if ( stream->read )
@@ -153,7 +153,7 @@
" invalid read; expected %lu bytes, got %lu\n",
count, read_bytes ));
- error = FT_Err_Invalid_Stream_Operation;
+ error = FT_THROW( Invalid_Stream_Operation );
}
return error;
@@ -246,6 +246,18 @@
/* allocate the frame in memory */
FT_Memory memory = stream->memory;
+
+ /* simple sanity check */
+ if ( count > stream->size )
+ {
+ FT_ERROR(( "FT_Stream_EnterFrame:"
+ " frame size (%lu) larger than stream size (%lu)\n",
+ count, stream->size ));
+
+ error = FT_THROW( Invalid_Stream_Operation );
+ goto Exit;
+ }
+
#ifdef FT_DEBUG_MEMORY
/* assume _ft_debug_file and _ft_debug_lineno are already set */
stream->base = (unsigned char*)ft_mem_qalloc( memory, count, &error );
@@ -265,7 +277,7 @@
count, read_bytes ));
FT_FREE( stream->base );
- error = FT_Err_Invalid_Stream_Operation;
+ error = FT_THROW( Invalid_Stream_Operation );
}
stream->cursor = stream->base;
stream->limit = stream->cursor + count;
@@ -275,13 +287,13 @@
{
/* check current and new position */
if ( stream->pos >= stream->size ||
- stream->pos + count > stream->size )
+ stream->size - stream->pos < count )
{
FT_ERROR(( "FT_Stream_EnterFrame:"
" invalid i/o; pos = 0x%lx, count = %lu, size = 0x%lx\n",
stream->pos, count, stream->size ));
- error = FT_Err_Invalid_Stream_Operation;
+ error = FT_THROW( Invalid_Stream_Operation );
goto Exit;
}
@@ -342,8 +354,8 @@
}
- FT_BASE_DEF( FT_Short )
- FT_Stream_GetShort( FT_Stream stream )
+ FT_BASE_DEF( FT_UShort )
+ FT_Stream_GetUShort( FT_Stream stream )
{
FT_Byte* p;
FT_Short result;
@@ -354,15 +366,15 @@
result = 0;
p = stream->cursor;
if ( p + 1 < stream->limit )
- result = FT_NEXT_SHORT( p );
+ result = FT_NEXT_USHORT( p );
stream->cursor = p;
return result;
}
- FT_BASE_DEF( FT_Short )
- FT_Stream_GetShortLE( FT_Stream stream )
+ FT_BASE_DEF( FT_UShort )
+ FT_Stream_GetUShortLE( FT_Stream stream )
{
FT_Byte* p;
FT_Short result;
@@ -373,15 +385,15 @@
result = 0;
p = stream->cursor;
if ( p + 1 < stream->limit )
- result = FT_NEXT_SHORT_LE( p );
+ result = FT_NEXT_USHORT_LE( p );
stream->cursor = p;
return result;
}
- FT_BASE_DEF( FT_Long )
- FT_Stream_GetOffset( FT_Stream stream )
+ FT_BASE_DEF( FT_ULong )
+ FT_Stream_GetUOffset( FT_Stream stream )
{
FT_Byte* p;
FT_Long result;
@@ -392,14 +404,14 @@
result = 0;
p = stream->cursor;
if ( p + 2 < stream->limit )
- result = FT_NEXT_OFF3( p );
+ result = FT_NEXT_UOFF3( p );
stream->cursor = p;
return result;
}
- FT_BASE_DEF( FT_Long )
- FT_Stream_GetLong( FT_Stream stream )
+ FT_BASE_DEF( FT_ULong )
+ FT_Stream_GetULong( FT_Stream stream )
{
FT_Byte* p;
FT_Long result;
@@ -410,14 +422,14 @@
result = 0;
p = stream->cursor;
if ( p + 3 < stream->limit )
- result = FT_NEXT_LONG( p );
+ result = FT_NEXT_ULONG( p );
stream->cursor = p;
return result;
}
- FT_BASE_DEF( FT_Long )
- FT_Stream_GetLongLE( FT_Stream stream )
+ FT_BASE_DEF( FT_ULong )
+ FT_Stream_GetULongLE( FT_Stream stream )
{
FT_Byte* p;
FT_Long result;
@@ -428,7 +440,7 @@
result = 0;
p = stream->cursor;
if ( p + 3 < stream->limit )
- result = FT_NEXT_LONG_LE( p );
+ result = FT_NEXT_ULONG_LE( p );
stream->cursor = p;
return result;
}
@@ -462,7 +474,7 @@
return result;
Fail:
- *error = FT_Err_Invalid_Stream_Operation;
+ *error = FT_THROW( Invalid_Stream_Operation );
FT_ERROR(( "FT_Stream_ReadChar:"
" invalid i/o; pos = 0x%lx, size = 0x%lx\n",
stream->pos, stream->size ));
@@ -471,8 +483,8 @@
}
- FT_BASE_DEF( FT_Short )
- FT_Stream_ReadShort( FT_Stream stream,
+ FT_BASE_DEF( FT_UShort )
+ FT_Stream_ReadUShort( FT_Stream stream,
FT_Error* error )
{
FT_Byte reads[2];
@@ -499,7 +511,7 @@
}
if ( p )
- result = FT_NEXT_SHORT( p );
+ result = FT_NEXT_USHORT( p );
}
else
goto Fail;
@@ -509,8 +521,8 @@
return result;
Fail:
- *error = FT_Err_Invalid_Stream_Operation;
- FT_ERROR(( "FT_Stream_ReadShort:"
+ *error = FT_THROW( Invalid_Stream_Operation );
+ FT_ERROR(( "FT_Stream_ReadUShort:"
" invalid i/o; pos = 0x%lx, size = 0x%lx\n",
stream->pos, stream->size ));
@@ -518,8 +530,8 @@
}
- FT_BASE_DEF( FT_Short )
- FT_Stream_ReadShortLE( FT_Stream stream,
+ FT_BASE_DEF( FT_UShort )
+ FT_Stream_ReadUShortLE( FT_Stream stream,
FT_Error* error )
{
FT_Byte reads[2];
@@ -546,7 +558,7 @@
}
if ( p )
- result = FT_NEXT_SHORT_LE( p );
+ result = FT_NEXT_USHORT_LE( p );
}
else
goto Fail;
@@ -556,8 +568,8 @@
return result;
Fail:
- *error = FT_Err_Invalid_Stream_Operation;
- FT_ERROR(( "FT_Stream_ReadShortLE:"
+ *error = FT_THROW( Invalid_Stream_Operation );
+ FT_ERROR(( "FT_Stream_ReadUShortLE:"
" invalid i/o; pos = 0x%lx, size = 0x%lx\n",
stream->pos, stream->size ));
@@ -565,8 +577,8 @@
}
- FT_BASE_DEF( FT_Long )
- FT_Stream_ReadOffset( FT_Stream stream,
+ FT_BASE_DEF( FT_ULong )
+ FT_Stream_ReadUOffset( FT_Stream stream,
FT_Error* error )
{
FT_Byte reads[3];
@@ -593,7 +605,7 @@
}
if ( p )
- result = FT_NEXT_OFF3( p );
+ result = FT_NEXT_UOFF3( p );
}
else
goto Fail;
@@ -603,8 +615,8 @@
return result;
Fail:
- *error = FT_Err_Invalid_Stream_Operation;
- FT_ERROR(( "FT_Stream_ReadOffset:"
+ *error = FT_THROW( Invalid_Stream_Operation );
+ FT_ERROR(( "FT_Stream_ReadUOffset:"
" invalid i/o; pos = 0x%lx, size = 0x%lx\n",
stream->pos, stream->size ));
@@ -612,8 +624,8 @@
}
- FT_BASE_DEF( FT_Long )
- FT_Stream_ReadLong( FT_Stream stream,
+ FT_BASE_DEF( FT_ULong )
+ FT_Stream_ReadULong( FT_Stream stream,
FT_Error* error )
{
FT_Byte reads[4];
@@ -640,7 +652,7 @@
}
if ( p )
- result = FT_NEXT_LONG( p );
+ result = FT_NEXT_ULONG( p );
}
else
goto Fail;
@@ -650,8 +662,8 @@
return result;
Fail:
- *error = FT_Err_Invalid_Stream_Operation;
- FT_ERROR(( "FT_Stream_ReadLong:"
+ *error = FT_THROW( Invalid_Stream_Operation );
+ FT_ERROR(( "FT_Stream_ReadULong:"
" invalid i/o; pos = 0x%lx, size = 0x%lx\n",
stream->pos, stream->size ));
@@ -659,8 +671,8 @@
}
- FT_BASE_DEF( FT_Long )
- FT_Stream_ReadLongLE( FT_Stream stream,
+ FT_BASE_DEF( FT_ULong )
+ FT_Stream_ReadULongLE( FT_Stream stream,
FT_Error* error )
{
FT_Byte reads[4];
@@ -687,7 +699,7 @@
}
if ( p )
- result = FT_NEXT_LONG_LE( p );
+ result = FT_NEXT_ULONG_LE( p );
}
else
goto Fail;
@@ -697,8 +709,8 @@
return result;
Fail:
- *error = FT_Err_Invalid_Stream_Operation;
- FT_ERROR(( "FT_Stream_ReadLongLE:"
+ *error = FT_THROW( Invalid_Stream_Operation );
+ FT_ERROR(( "FT_Stream_ReadULongLE:"
" invalid i/o; pos = 0x%lx, size = 0x%lx\n",
stream->pos, stream->size ));
@@ -715,8 +727,12 @@
FT_Bool frame_accessed = 0;
FT_Byte* cursor;
- if ( !fields || !stream )
- return FT_Err_Invalid_Argument;
+
+ if ( !fields )
+ return FT_THROW( Invalid_Argument );
+
+ if ( !stream )
+ return FT_THROW( Invalid_Stream_Handle );
cursor = stream->cursor;
@@ -748,7 +764,7 @@
if ( cursor + len > stream->limit )
{
- error = FT_Err_Invalid_Stream_Operation;
+ error = FT_THROW( Invalid_Stream_Operation );
goto Exit;
}
@@ -764,43 +780,43 @@
case ft_frame_byte:
case ft_frame_schar: /* read a single byte */
- value = FT_NEXT_BYTE(cursor);
+ value = FT_NEXT_BYTE( cursor );
sign_shift = 24;
break;
case ft_frame_short_be:
case ft_frame_ushort_be: /* read a 2-byte big-endian short */
- value = FT_NEXT_USHORT(cursor);
+ value = FT_NEXT_USHORT( cursor) ;
sign_shift = 16;
break;
case ft_frame_short_le:
case ft_frame_ushort_le: /* read a 2-byte little-endian short */
- value = FT_NEXT_USHORT_LE(cursor);
+ value = FT_NEXT_USHORT_LE( cursor );
sign_shift = 16;
break;
case ft_frame_long_be:
case ft_frame_ulong_be: /* read a 4-byte big-endian long */
- value = FT_NEXT_ULONG(cursor);
+ value = FT_NEXT_ULONG( cursor );
sign_shift = 0;
break;
case ft_frame_long_le:
case ft_frame_ulong_le: /* read a 4-byte little-endian long */
- value = FT_NEXT_ULONG_LE(cursor);
+ value = FT_NEXT_ULONG_LE( cursor );
sign_shift = 0;
break;
case ft_frame_off3_be:
case ft_frame_uoff3_be: /* read a 3-byte big-endian long */
- value = FT_NEXT_UOFF3(cursor);
+ value = FT_NEXT_UOFF3( cursor );
sign_shift = 8;
break;
case ft_frame_off3_le:
case ft_frame_uoff3_le: /* read a 3-byte little-endian long */
- value = FT_NEXT_UOFF3_LE(cursor);
+ value = FT_NEXT_UOFF3_LE( cursor );
sign_shift = 8;
break;
@@ -819,15 +835,15 @@
p = (FT_Byte*)structure + fields->offset;
switch ( fields->size )
{
- case (8 / FT_CHAR_BIT):
+ case ( 8 / FT_CHAR_BIT ):
*(FT_Byte*)p = (FT_Byte)value;
break;
- case (16 / FT_CHAR_BIT):
+ case ( 16 / FT_CHAR_BIT ):
*(FT_UShort*)p = (FT_UShort)value;
break;
- case (32 / FT_CHAR_BIT):
+ case ( 32 / FT_CHAR_BIT ):
*(FT_UInt32*)p = (FT_UInt32)value;
break;