Skip to content
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

[tx] cffread CFF2 fails with extra names in post 2.0 #1045

Closed
blueshade7 opened this issue Dec 6, 2019 · 1 comment · Fixed by #1046
Closed

[tx] cffread CFF2 fails with extra names in post 2.0 #1045

blueshade7 opened this issue Dec 6, 2019 · 1 comment · Fixed by #1046
Assignees

Comments

@blueshade7
Copy link
Contributor

tx -cff2 fails with the attached CFF2 font.

% tx -cff2  SourceSansPro-Regular-cff2-A.otf
tx: --- SourceSansPro-Regular-cff2-A.otf
tx: (cfr) post 2.0: string data didn't reach end of table
tx: (cfr) client failed glyph parse

ots-sanitize reports no problem about the font.

The font contains only one glyph other than .notdef but the post table version 2.0 contains extra unused glyph names. This appears to be confusing cffread.

% spot -tpost SourceSansPro-Regular-cff2-A.otf
### [post] (00000420)
version           =2.0 (00020000)
italicAngle       =0.000 (00000000)
underlinePosition =-50
underlineThickness=50
isFixedPitch      =0
minMemType42      =0
maxMemType42      =0
minMemType1       =0
maxMemType1       =0
--- format 2.0
numberGlyphs=2
--- glyphNameIndex[glyphId]=value
[0]=0 [1]=259 
--- names[index]={len,<name>}
[0]={6,<Abreve>} [1]={11,<Abreveacute>} [2]={14,<Abrevedotbelow>} [3]={11,<Abrevegrave>} [4]={15,<Abrevehookabove>} [5]={11,<Abrevetilde>} [6]={6,<Acaron>} [7]={16,<Acircumflexacute>} [8]={19,<Acircumflexdotbelow>} [9]={16,<Acircumflexgrave>} 

SourceSansPro-Regular-cff2-A.otf.zip

@blueshade7
Copy link
Contributor Author

blueshade7 commented Dec 6, 2019

postReadcounts the number of names used by all glyphs in post 2.0 in variable strCount.

for (i = 0; i < numGlyphs; i++) {
unsigned short nid = read2(h);
h->post.fmt2.glyphNameIndex.array[i] = nid;
if (nid > 32767) {
message(h, "post 2.0: invalid name id (table ignored)");
goto parseError;
} else if (nid > 257)
strCount++;
}

Then copies this many strings from the beginning of the string area in the post table.
dnaSET_CNT(h->post.fmt2.strings, strCount);
p = h->post.fmt2.buf.array;
end = p + length;
for (i = 0; i < h->post.fmt2.strings.cnt; i++) {
length = *(uint8_t *)p;
*p++ = '\0';
h->post.fmt2.strings.array[i] = p;
p += length;
if (p > end) {
message(h, "post 2.0: invalid strings");
goto parseError;
}
}

If any unused names are included, used names that follow cannot be correctly looked up by post2GetName.
else if (nid - 258 >= h->post.fmt2.strings.cnt) {
return NULL; /* Out of bounds; .notdef */

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant