Fix a potential heap overflow in the TrueType cmap code.

This commit is contained in:
Michael R Sweet 2025-02-24 10:55:28 -05:00
parent 1237599dea
commit 89c2a75376
No known key found for this signature in database
GPG Key ID: BE67C75EC81F3244
2 changed files with 4 additions and 3 deletions

View File

@ -13,6 +13,7 @@ v1.5.0 - YYYY-MM-DD
- Added support for writing the PCLm subset of PDF (Issue #99)
- Now support opening damaged PDF files (Issue #45)
- Updated the pdf2txt example to support font encodings.
- Fixed a potential heap overflow in the TrueType font code.
v1.4.1 - 2025-01-24

6
ttf.c
View File

@ -3,7 +3,7 @@
//
// https://github.com/michaelrsweet/ttf
//
// Copyright © 2018-2024 by Michael R Sweet.
// Copyright © 2018-2025 by Michael R Sweet.
//
// Licensed under Apache License v2.0. See the file "LICENSE" for more
// information.
@ -1460,7 +1460,7 @@ read_cmap(ttf_t *font) // I - Font
// array...
for (gidx = 0, group = groups; gidx < nGroups; gidx ++, group ++)
{
for (ch = group->startCharCode; ch <= group->endCharCode && ch < TTF_FONT_MAX_CHAR; ch ++)
for (ch = group->startCharCode; ch <= group->endCharCode && ch < font->num_cmap; ch ++)
cmapptr[ch] = (int)(group->startGlyphID + ch - group->startCharCode);
}
@ -1551,7 +1551,7 @@ read_cmap(ttf_t *font) // I - Font
// array...
for (gidx = 0, group = groups; gidx < nGroups; gidx ++, group ++)
{
for (ch = group->startCharCode; ch <= group->endCharCode && ch < TTF_FONT_MAX_CHAR; ch ++)
for (ch = group->startCharCode; ch <= group->endCharCode && ch < font->num_cmap; ch ++)
cmapptr[ch] = (int)group->glyphID;
}