Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Add protection against out-of-bounds read in ttconv #20629

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 30 additions & 27 deletions extern/ttconv/pprdrv_tt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -757,33 +757,36 @@ void ttfont_sfnts(TTStreamWriter& stream, struct TTFONT *font)
** Find the tables we want and store there vital
** statistics in tables[].
*/
for (x=0; x < 9; x++ )
{
do
{
diff = strncmp( (char*)ptr, table_names[x], 4 );

if ( diff > 0 ) /* If we are past it. */
{
tables[x].length = 0;
diff = 0;
}
else if ( diff < 0 ) /* If we haven't hit it yet. */
{
ptr += 16;
}
else if ( diff == 0 ) /* Here it is! */
{
tables[x].newoffset = nextoffset;
tables[x].checksum = getULONG( ptr + 4 );
tables[x].oldoffset = getULONG( ptr + 8 );
tables[x].length = getULONG( ptr + 12 );
nextoffset += ( ((tables[x].length + 3) / 4) * 4 );
count++;
ptr += 16;
}
}
while (diff != 0);
ULONG num_tables_read = 0; /* Number of tables read from the directory */
for (x = 0; x < 9; x++) {
do {
if (num_tables_read < font->numTables) {
/* There are still tables to read from ptr */
diff = strncmp((char*)ptr, table_names[x], 4);

if (diff > 0) { /* If we are past it. */
tables[x].length = 0;
diff = 0;
} else if (diff < 0) { /* If we haven't hit it yet. */
ptr += 16;
num_tables_read++;
} else if (diff == 0) { /* Here it is! */
tables[x].newoffset = nextoffset;
tables[x].checksum = getULONG( ptr + 4 );
tables[x].oldoffset = getULONG( ptr + 8 );
tables[x].length = getULONG( ptr + 12 );
nextoffset += ( ((tables[x].length + 3) / 4) * 4 );
count++;
ptr += 16;
num_tables_read++;
}
} else {
/* We've read the whole table directory already */
/* Some tables couldn't be found */
tables[x].length = 0;
break; /* Proceed to next tables[x] */
}
} while (diff != 0);

} /* end of for loop which passes over the table directory */

Expand Down
Loading