[gxvalid] Fix gcc4.6 compiler warnings in gxvjust.c.

* src/gxvalid/gxvjust.c (gxv_just_check_max_gid):
New function to unify the checks of too large GID.
(gxv_just_wdp_entry_validate): Conditionalize unvalidated
variables; `beforeGrowLimit', `beforeShrinkGrowLimit',
`afterGrowLimit', `afterShrinkGrowLimit', `growFlags',
`shrinkFlags'.  Additional check for non-zero values in
unused storage `justClass' is added.
(gxv_just_actSubrecord_type0_validate): Conditionalize
unvalidated variable `order'.  GID is checked by
gxv_just_check_max_gid().  Additional check for upside-down
relationship between `lowerLimit' and `upperLimit' is added.
(gxv_just_actSubrecord_type1_validate): GID is checked by
gxv_just_check_max_gid().
(gxv_just_actSubrecord_type2_validate): Conditionalize
unvalidated variable `substThreshhold'.  GID is checked by
gxv_just_check_max_gid().
(gxv_just_actSubrecord_type5_validate): GID is checked by
gxv_just_check_max_gid().
(gxv_just_classTable_entry_validate): Conditionalize
unvalidated variables; `setMark', `dontAdvance',
`markClass', `currentClass'.
This commit is contained in:
suzuki toshiya 2011-06-14 23:49:34 +09:00
parent 248aa63973
commit ce015ec8da
2 changed files with 127 additions and 10 deletions

View File

@ -1,3 +1,29 @@
2011-06-14 suzuki toshiya <mpsuzuki@hiroshima-u.ac.jp>
[gxvalid] Fix gcc4.6 compiler warnings in gxvjust.c.
* src/gxvalid/gxvjust.c (gxv_just_check_max_gid):
New function to unify the checks of too large GID.
(gxv_just_wdp_entry_validate): Conditionalize unvalidated
variables; `beforeGrowLimit', `beforeShrinkGrowLimit',
`afterGrowLimit', `afterShrinkGrowLimit', `growFlags',
`shrinkFlags'. Additional check for non-zero values in
unused storage `justClass' is added.
(gxv_just_actSubrecord_type0_validate): Conditionalize
unvalidated variable `order'. GID is checked by
gxv_just_check_max_gid(). Additional check for upside-down
relationship between `lowerLimit' and `upperLimit' is added.
(gxv_just_actSubrecord_type1_validate): GID is checked by
gxv_just_check_max_gid().
(gxv_just_actSubrecord_type2_validate): Conditionalize
unvalidated variable `substThreshhold'. GID is checked by
gxv_just_check_max_gid().
(gxv_just_actSubrecord_type5_validate): GID is checked by
gxv_just_check_max_gid().
(gxv_just_classTable_entry_validate): Conditionalize
unvalidated variables; `setMark', `dontAdvance',
`markClass', `currentClass'.
2011-06-14 suzuki toshiya <mpsuzuki@hiroshima-u.ac.jp> 2011-06-14 suzuki toshiya <mpsuzuki@hiroshima-u.ac.jp>
[gxvalid] Preparation to fix gcc4.6 compiler warnings. [gxvalid] Preparation to fix gcc4.6 compiler warnings.

View File

@ -65,6 +65,23 @@
#define GXV_JUST_DATA( a ) GXV_TABLE_DATA( just, a ) #define GXV_JUST_DATA( a ) GXV_TABLE_DATA( just, a )
/* GX just table does not define their subset of GID */
static void
gxv_just_check_max_gid( FT_UShort gid,
const FT_String* msg_tag,
GXV_Validator valid )
{
if ( gid < valid->face->num_glyphs )
return;
GXV_TRACE(( "just table includes too large %s"
" GID=%d > %d (in maxp)\n",
msg_tag, gid, valid->face->num_glyphs ));
if ( valid->root->level >= FT_VALIDATE_PARANOID )
FT_INVALID_GLYPH_ID;
}
static void static void
gxv_just_wdp_entry_validate( FT_Bytes table, gxv_just_wdp_entry_validate( FT_Bytes table,
FT_Bytes limit, FT_Bytes limit,
@ -72,24 +89,38 @@
{ {
FT_Bytes p = table; FT_Bytes p = table;
FT_ULong justClass; FT_ULong justClass;
#ifdef GXV_LOAD_UNUSED_VARS
FT_Fixed beforeGrowLimit; FT_Fixed beforeGrowLimit;
FT_Fixed beforeShrinkGrowLimit; FT_Fixed beforeShrinkGrowLimit;
FT_Fixed afterGrowLimit; FT_Fixed afterGrowLimit;
FT_Fixed afterShrinkGrowLimit; FT_Fixed afterShrinkGrowLimit;
FT_UShort growFlags; FT_UShort growFlags;
FT_UShort shrinkFlags; FT_UShort shrinkFlags;
#endif
GXV_LIMIT_CHECK( 4 + 4 + 4 + 4 + 4 + 2 + 2 ); GXV_LIMIT_CHECK( 4 + 4 + 4 + 4 + 4 + 2 + 2 );
justClass = FT_NEXT_ULONG( p ); justClass = FT_NEXT_ULONG( p );
#ifndef GXV_LOAD_UNUSED_VARS
p += 4 + 4 + 4 + 4 + 2 + 2;
#else
beforeGrowLimit = FT_NEXT_ULONG( p ); beforeGrowLimit = FT_NEXT_ULONG( p );
beforeShrinkGrowLimit = FT_NEXT_ULONG( p ); beforeShrinkGrowLimit = FT_NEXT_ULONG( p );
afterGrowLimit = FT_NEXT_ULONG( p ); afterGrowLimit = FT_NEXT_ULONG( p );
afterShrinkGrowLimit = FT_NEXT_ULONG( p ); afterShrinkGrowLimit = FT_NEXT_ULONG( p );
growFlags = FT_NEXT_USHORT( p ); growFlags = FT_NEXT_USHORT( p );
shrinkFlags = FT_NEXT_USHORT( p ); shrinkFlags = FT_NEXT_USHORT( p );
#endif
/* TODO: decode flags for human readability */ /* According to Apple spec, only 7bits in justClass is used */
if ( valid->root->level >= FT_VALIDATE_PARANOID &&
( justClass & 0xFFFFFF80 ) != 0 )
{
GXV_TRACE(( "just table includes non-zero value"
" in unused justClass higher bits"
" of WidthDeltaPair" ));
FT_INVALID_DATA;
}
valid->subtable_length = p - table; valid->subtable_length = p - table;
} }
@ -153,8 +184,9 @@
FT_Fixed lowerLimit; FT_Fixed lowerLimit;
FT_Fixed upperLimit; FT_Fixed upperLimit;
#ifdef GXV_LOAD_UNUSED_VARS
FT_UShort order; FT_UShort order;
#endif
FT_UShort decomposedCount; FT_UShort decomposedCount;
FT_UInt i; FT_UInt i;
@ -163,9 +195,21 @@
GXV_LIMIT_CHECK( 4 + 4 + 2 + 2 ); GXV_LIMIT_CHECK( 4 + 4 + 2 + 2 );
lowerLimit = FT_NEXT_ULONG( p ); lowerLimit = FT_NEXT_ULONG( p );
upperLimit = FT_NEXT_ULONG( p ); upperLimit = FT_NEXT_ULONG( p );
#ifdef GXV_LOAD_UNUSED_VARS
order = FT_NEXT_USHORT( p ); order = FT_NEXT_USHORT( p );
#else
p += 2;
#endif
decomposedCount = FT_NEXT_USHORT( p ); decomposedCount = FT_NEXT_USHORT( p );
if ( valid->root->level >= FT_VALIDATE_PARANOID &&
lowerLimit >= upperLimit )
{
GXV_TRACE(( "just table includes invalid range spec:"
" lowerLimit(%d) > upperLimit(%d)\n" ));
FT_INVALID_DATA;
}
for ( i = 0; i < decomposedCount; i++ ) for ( i = 0; i < decomposedCount; i++ )
{ {
FT_UShort glyphs; FT_UShort glyphs;
@ -173,6 +217,7 @@
GXV_LIMIT_CHECK( 2 ); GXV_LIMIT_CHECK( 2 );
glyphs = FT_NEXT_USHORT( p ); glyphs = FT_NEXT_USHORT( p );
gxv_just_check_max_gid( glyphs, "type0:glyphs", valid );
} }
valid->subtable_length = p - table; valid->subtable_length = p - table;
@ -191,6 +236,8 @@
GXV_LIMIT_CHECK( 2 ); GXV_LIMIT_CHECK( 2 );
addGlyph = FT_NEXT_USHORT( p ); addGlyph = FT_NEXT_USHORT( p );
gxv_just_check_max_gid( addGlyph, "type1:addGlyph", valid );
valid->subtable_length = p - table; valid->subtable_length = p - table;
} }
@ -201,16 +248,27 @@
GXV_Validator valid ) GXV_Validator valid )
{ {
FT_Bytes p = table; FT_Bytes p = table;
#ifdef GXV_LOAD_UNUSED_VARS
FT_Fixed substThreshhold; /* Apple misspelled "Threshhold" */ FT_Fixed substThreshhold; /* Apple misspelled "Threshhold" */
#endif
FT_UShort addGlyph; FT_UShort addGlyph;
FT_UShort substGlyph; FT_UShort substGlyph;
GXV_LIMIT_CHECK( 4 + 2 + 2 ); GXV_LIMIT_CHECK( 4 + 2 + 2 );
#ifdef GXV_LOAD_UNUSED_VARS
substThreshhold = FT_NEXT_ULONG( p ); substThreshhold = FT_NEXT_ULONG( p );
#else
p += 4;
#endif
addGlyph = FT_NEXT_USHORT( p ); addGlyph = FT_NEXT_USHORT( p );
substGlyph = FT_NEXT_USHORT( p ); substGlyph = FT_NEXT_USHORT( p );
if ( addGlyph != 0xFFFF )
gxv_just_check_max_gid( addGlyph, "type2:addGlyph", valid );
gxv_just_check_max_gid( substGlyph, "type2:substGlyph", valid );
valid->subtable_length = p - table; valid->subtable_length = p - table;
} }
@ -234,6 +292,21 @@
maximumLimit = FT_NEXT_ULONG( p ); maximumLimit = FT_NEXT_ULONG( p );
valid->subtable_length = p - table; valid->subtable_length = p - table;
if ( variantsAxis != 0x64756374 ) /* 'duct' */
GXV_TRACE(( "variantsAxis 0x%08x is non default value",
variantsAxis ));
if ( minimumLimit > noStretchValue )
GXV_TRACE(( "type4:minimumLimit 0x%08x > noStretchValue 0x%08x\n",
minimumLimit, noStretchValue ));
else if ( noStretchValue > maximumLimit )
GXV_TRACE(( "type4:noStretchValue 0x%08x > maximumLimit 0x%08x\n",
noStretchValue, maximumLimit ));
else if ( valid->root->level < FT_VALIDATE_PARANOID )
return;
FT_INVALID_DATA;
} }
@ -251,6 +324,11 @@
flags = FT_NEXT_USHORT( p ); flags = FT_NEXT_USHORT( p );
glyph = FT_NEXT_USHORT( p ); glyph = FT_NEXT_USHORT( p );
if ( flags )
GXV_TRACE(( "type5: nonzero value 0x%04x in unused flags\n",
flags ));
gxv_just_check_max_gid( glyph, "type5:glyph", valid );
valid->subtable_length = p - table; valid->subtable_length = p - table;
} }
@ -274,6 +352,11 @@
actionType = FT_NEXT_USHORT( p ); actionType = FT_NEXT_USHORT( p );
actionLength = FT_NEXT_ULONG( p ); actionLength = FT_NEXT_ULONG( p );
/* actionClass is related with justClass using 7bit only */
if ( valid->root->level >= FT_VALIDATE_PARANOID &&
( actionClass & 0xFF80 ) != 0 )
FT_INVALID_DATA;
if ( actionType == 0 ) if ( actionType == 0 )
gxv_just_actSubrecord_type0_validate( p, limit, valid ); gxv_just_actSubrecord_type0_validate( p, limit, valid );
else if ( actionType == 1 ) else if ( actionType == 1 )
@ -389,10 +472,13 @@
FT_Bytes limit, FT_Bytes limit,
GXV_Validator valid ) GXV_Validator valid )
{ {
#ifdef GXV_LOAD_UNUSED_VARS
/* TODO: validate markClass & currentClass */
FT_UShort setMark; FT_UShort setMark;
FT_UShort dontAdvance; FT_UShort dontAdvance;
FT_UShort markClass; FT_UShort markClass;
FT_UShort currentClass; FT_UShort currentClass;
#endif
FT_UNUSED( state ); FT_UNUSED( state );
FT_UNUSED( glyphOffset_p ); FT_UNUSED( glyphOffset_p );
@ -400,13 +486,14 @@
FT_UNUSED( limit ); FT_UNUSED( limit );
FT_UNUSED( valid ); FT_UNUSED( valid );
#ifndef GXV_LOAD_UNUSED_VARS
FT_UNUSED( flags );
#else
setMark = (FT_UShort)( ( flags >> 15 ) & 1 ); setMark = (FT_UShort)( ( flags >> 15 ) & 1 );
dontAdvance = (FT_UShort)( ( flags >> 14 ) & 1 ); dontAdvance = (FT_UShort)( ( flags >> 14 ) & 1 );
markClass = (FT_UShort)( ( flags >> 7 ) & 0x7F ); markClass = (FT_UShort)( ( flags >> 7 ) & 0x7F );
currentClass = (FT_UShort)( flags & 0x7F ); currentClass = (FT_UShort)( flags & 0x7F );
#endif
/* TODO: validate markClass & currentClass */
} }
@ -428,9 +515,15 @@
coverage = FT_NEXT_USHORT( p ); coverage = FT_NEXT_USHORT( p );
subFeatureFlags = FT_NEXT_ULONG( p ); subFeatureFlags = FT_NEXT_ULONG( p );
GXV_TRACE(( " justClassTable: coverage = 0x%04x (%s)", GXV_TRACE(( " justClassTable: coverage = 0x%04x (%s) ", coverage ));
coverage, if ( ( coverage & 0x4000 ) == 0 )
( 0x4000 & coverage ) == 0 ? "ascending" : "descending" )); GXV_TRACE(( "ascending\n" ));
else
GXV_TRACE(( "descending\n" ));
if ( subFeatureFlags )
GXV_TRACE(( " justClassTable: nonzero value (0x%08x)"
" in unused subFeatureFlags\n", subFeatureFlags ));
valid->statetable.optdata = NULL; valid->statetable.optdata = NULL;
valid->statetable.optdata_load_func = NULL; valid->statetable.optdata_load_func = NULL;
@ -557,7 +650,6 @@
{ {
FT_Bytes p = table; FT_Bytes p = table;
FT_Bytes limit = 0; FT_Bytes limit = 0;
FT_Offset table_size;
GXV_ValidatorRec validrec; GXV_ValidatorRec validrec;
GXV_Validator valid = &validrec; GXV_Validator valid = &validrec;
@ -582,7 +674,6 @@
GXV_INIT; GXV_INIT;
limit = valid->root->limit; limit = valid->root->limit;
table_size = limit - table;
GXV_LIMIT_CHECK( 4 + 2 + 2 + 2 ); GXV_LIMIT_CHECK( 4 + 2 + 2 + 2 );
version = FT_NEXT_ULONG( p ); version = FT_NEXT_ULONG( p );