Skip to content

Commit a518b74

Browse files
authored
Merge pull request #20642 from meeseeksmachine/auto-backport-of-pr-20629-on-v3.4.x
Backport PR #20629 on branch v3.4.x (Add protection against out-of-bounds read in ttconv)
2 parents 0a9139e + 649c07d commit a518b74

File tree

3 files changed

+21228
-27
lines changed

3 files changed

+21228
-27
lines changed

extern/ttconv/pprdrv_tt.cpp

Lines changed: 30 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -798,33 +798,36 @@ void ttfont_sfnts(TTStreamWriter& stream, struct TTFONT *font)
798798
** Find the tables we want and store there vital
799799
** statistics in tables[].
800800
*/
801-
for (x=0; x < 9; x++ )
802-
{
803-
do
804-
{
805-
diff = strncmp( (char*)ptr, table_names[x], 4 );
806-
807-
if ( diff > 0 ) /* If we are past it. */
808-
{
809-
tables[x].length = 0;
810-
diff = 0;
811-
}
812-
else if ( diff < 0 ) /* If we haven't hit it yet. */
813-
{
814-
ptr += 16;
815-
}
816-
else if ( diff == 0 ) /* Here it is! */
817-
{
818-
tables[x].newoffset = nextoffset;
819-
tables[x].checksum = getULONG( ptr + 4 );
820-
tables[x].oldoffset = getULONG( ptr + 8 );
821-
tables[x].length = getULONG( ptr + 12 );
822-
nextoffset += ( ((tables[x].length + 3) / 4) * 4 );
823-
count++;
824-
ptr += 16;
825-
}
826-
}
827-
while (diff != 0);
801+
ULONG num_tables_read = 0; /* Number of tables read from the directory */
802+
for (x = 0; x < 9; x++) {
803+
do {
804+
if (num_tables_read < font->numTables) {
805+
/* There are still tables to read from ptr */
806+
diff = strncmp((char*)ptr, table_names[x], 4);
807+
808+
if (diff > 0) { /* If we are past it. */
809+
tables[x].length = 0;
810+
diff = 0;
811+
} else if (diff < 0) { /* If we haven't hit it yet. */
812+
ptr += 16;
813+
num_tables_read++;
814+
} else if (diff == 0) { /* Here it is! */
815+
tables[x].newoffset = nextoffset;
816+
tables[x].checksum = getULONG( ptr + 4 );
817+
tables[x].oldoffset = getULONG( ptr + 8 );
818+
tables[x].length = getULONG( ptr + 12 );
819+
nextoffset += ( ((tables[x].length + 3) / 4) * 4 );
820+
count++;
821+
ptr += 16;
822+
num_tables_read++;
823+
}
824+
} else {
825+
/* We've read the whole table directory already */
826+
/* Some tables couldn't be found */
827+
tables[x].length = 0;
828+
break; /* Proceed to next tables[x] */
829+
}
830+
} while (diff != 0);
828831

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

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy