Skip to content

Commit 339db4f

Browse files
authored
adding safeguards so input of oxffff glyph id isn't problematic (#256)
1 parent 4b59b82 commit 339db4f

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

PDFWriter/TrueTypeDescendentFontWriter.cpp

+6-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "TrueTypeEmbeddedFontWriter.h"
2525
#include "ObjectsContext.h"
2626
#include "IndirectObjectsReferenceRegistry.h"
27+
#include "Trace.h"
2728

2829
using namespace PDFHummus;
2930

@@ -55,14 +56,18 @@ EStatusCode TrueTypeDescendentFontWriter::WriteFont( ObjectIDType inDecendentObj
5556
// reset embedded font object ID (and flag...to whether it was actually embedded or not, which may
5657
// happen due to font embedding restrictions)
5758
mEmbeddedFontFileObjectID = 0;
59+
if(inEncodedGlyphs.back().first == 0xFFFF) {
60+
TRACE_LOG("TrueTypeDescendentFontWriter::WriteFont, glyphs list includes a glyph id of 0xFFFF which is out of bounds for true type");
61+
return eFailure;
62+
}
5863
unsigned int subsetFontSize = inEncodedGlyphs.back().first + 1;
5964

6065
if (inEmbedFont)
6166
{
6267
TrueTypeEmbeddedFontWriter embeddedFontWriter;
6368
EStatusCode status = embeddedFontWriter.WriteEmbeddedFont(inFontInfo, GetOrderedKeys(inEncodedGlyphs), inObjectsContext, mEmbeddedFontFileObjectID);
6469

65-
if (PDFHummus::eFailure == status)
70+
if (eFailure == status)
6671
return status;
6772

6873
// subset font size may have changed due to the inclusion of dependent glyphs

PDFWriter/TrueTypeEmbeddedFontWriter.cpp

+8-1
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,14 @@ EStatusCode TrueTypeEmbeddedFontWriter::CreateTrueTypeSubset( FreeTypeFaceWrappe
154154
// so - bottom line - the glyphs count will actually be 1 more than the maxium glyph index.
155155
// and from here i'll just place the glyphs in their original indexes, and fill in the
156156
// vacant glyphs with empties.
157-
mSubsetFontGlyphsCount = subsetGlyphIDs.back() + 1;
157+
unsigned short maxGlyf = subsetGlyphIDs.back();
158+
if(maxGlyf >= mTrueTypeInput.mMaxp.NumGlyphs)
159+
{
160+
TRACE_LOG2("TrueTypeEmbeddedFontWriter::CreateTrueTypeSubset, error, maximum requested glyph index %ld is larger than the maximum glyph index for this font which is %ld. ",maxGlyf,mTrueTypeInput.mMaxp.NumGlyphs-1);
161+
status = eFailure;
162+
break;
163+
}
164+
mSubsetFontGlyphsCount = maxGlyf + 1;
158165

159166
mFontFileStream.Assign(&outFontProgram);
160167
mPrimitivesWriter.SetOpenTypeStream(&mFontFileStream);

0 commit comments

Comments
 (0)