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

Galk.interpreters.limits implementation #247

Merged
merged 2 commits into from Jan 6, 2024

Conversation

galkahana
Copy link
Owner

Following a recent look into type2 fonts implementation in the library i realized there's not much there by way of securing the usage of type2 and type1 fonts. they are interpreted in order to create relevant representations in and outcome pdf, but there's no checks into the validity of glyph operators within glyphs charstrings.
This can be be problematic if you are creating a PDF that includes a faulty (or even malicious) font. normally this would not be the case...you are using fonts that you know, but if you are a general purpose mechanism allowing users to submit their fonts, there's a bit of a chance that an erring font might find it's way into your mechanism.

then you would like protections from simple things like a glyph subroutine calling another one and it in turn calling back the source subroutine, which would create an endless loop. Or just reading 2 arguments from the stack for an or operator when there's just one.

hummus will now abort in such case, rather than just reading from places it shouldn't read, with a useful trace log so you know what happened.

To avoid subr endless loop i'm holding now type2 and type1 charstrings limitations, which requires a max depth of nesting of 10. There's also arguments limit (24 for type 1, 48 for type 1), and type 2 also defines a stem hint limit, so those are upheld as well, aborting in case a font breaches those limitations.

all this should protect users of the library that use fonts from unknown source a bit better.

note that this has nothing to do with the parser, this is a purely writer MR.

Also...found 2 errors. roll operator for type 2 and get operator for type 1 had errors in their implementations...not sure it had a really interesting effective meaning.

@galkahana galkahana merged commit b2ddf3f into master Jan 6, 2024
3 checks passed
@galkahana galkahana deleted the galk.interpreters.limits_implementation branch January 6, 2024 10:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant