static boolean VerifyResTableType ( ResTable_type header ) { if ( header . id == 0 ) { logError ( "RES_TABLE_TYPE_TYPE has invalid ID 0." ) ; return false ; } int entry_count = dtohl ( header . entryCount ) ; // if (entry_count > std.numeric_limits<uint16_t>.max()) { if ( entry_count > 0xffff ) { logError ( "RES_TABLE_TYPE_TYPE has too many entries (" + entry_count + ")." ) ; return false ; } // Make sure that there is enough room for the entry offsets. int offsets_offset = dtohs ( header . header . headerSize ) ; int entries_offset = dtohl ( header . entriesStart ) ; int offsets_length = 4 * entry_count ; if ( offsets_offset > entries_offset || entries_offset - offsets_offset < offsets_length ) { logError ( "RES_TABLE_TYPE_TYPE entry offsets overlap actual entry data." ) ; return false ; } if ( entries_offset > dtohl ( header . header . size ) ) { logError ( "RES_TABLE_TYPE_TYPE entry offsets extend beyond chunk." ) ; return false ; } if ( isTruthy ( entries_offset & 0x03 ) ) { logError ( "RES_TABLE_TYPE_TYPE entries start at unaligned address." ) ; return false ; } return true ; }
the ResChunk_header is safe .