Skip to content

Raise a clear error on incomplete Type1 font sections - #32193

Open
vsaraikin wants to merge 3 commits into
matplotlib:mainfrom
vsaraikin:fix/type1font-incomplete-sections
Open

Raise a clear error on incomplete Type1 font sections#32193
vsaraikin wants to merge 3 commits into
matplotlib:mainfrom
vsaraikin:fix/type1font-incomplete-sections

Conversation

@vsaraikin

Copy link
Copy Markdown
Contributor

Follow-up to #32062.

A truncated Type1 font raises a bare StopIteration out of the parser:

>>> Type1Font(path)
StopIteration:

Nothing about the file, no message at all. #32062 fixed that for /Subrs, since the review there asked for it. The three sibling parsers were left as they were, so /CharStrings, /Encoding and /OtherSubrs still do it on 3.11.1.

They now raise the same kind of error, for example RuntimeError("Malformed Type1 font file: Incomplete /CharStrings").

Most of the diff is the reindent from the try block. It reads much better with whitespace ignored, where it is 26 lines added and 5 removed.

Five parametrised cases cover the truncation points. All five fail on main

@QuLogic

QuLogic commented Aug 10, 2026

Copy link
Copy Markdown
Member

It seems reasonable to catch all of these, but would it be simpler to catch it at the call site instead of indenting everything?

@vsaraikin

Copy link
Copy Markdown
Contributor Author

Much better, thanks. The dispatch already knows the key so the message builds itself. It also covers all four parsers instead of three.

I dropped the try from _parse_subrs that #32062 added as well, since the call site now produces the same message for it. Ignoring whitespace the diff is 5 lines added and 5 removed, down from 26 and 5

Comment thread lib/matplotlib/_type1font.py Outdated
@QuLogic QuLogic added this to the v3.11.2 milestone Aug 12, 2026
@vsaraikin

Copy link
Copy Markdown
Contributor Author

Split, thanks. Only the call is inside the try now

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants