Repository navigation
Conversation
The TFM and OFM loaders used Max (n, 63) instead of Min (n, 63) to clamp the length of the font family. Since n comes from the font file, a length between 64 and 127 wrote past the 64-byte family array and corrupted the rest of TFMInfo. For short names, it also appended garbage from the header to the family name. Use Min(), so at most 63 bytes are copied. Taken from Evince commit 2af8b504efa6898639ce4c78c7515970aae7e126
The length of a GF xxx4 special is a 32-bit value read into an int. A crafted GF font could make it negative, which allocated a tiny buffer and then made fread() write past it. Hence, keep the length unsigned and reject lengths of INT_MAX or more. Additionally, handle a NULL result in gf_read_bitmap(), which passed it to mdvi_free() and aborted. Taken from Evince commit b2501fe8cdddaa90eb220058994355218e66e575
The length of a long_char packet is read into an int, so a crafted VF file could make it negative, or large enough to overflow the size of the buffer. In both cases fread() wrote past the end of the buffer. Treat those lengths as a corrupted file. Taken from Evince commit 33108259a7819c091dbaa56b013234aa63426db2
When a PK file ended after its first two bytes, the length of the comment was EOF, which became a huge unsigned length. The loop then copied bytes into a buffer on the stack until it crashed. Fail when the length cannot be read. Also, keep only the first 255 bytes of the specials (they are only used in a debug message), and stop reading them at EOF. Taken from Evince commit bc3bb1746d08d0506d85e262f193868bb8164d06
The decoder of packed PK glyphs trusted the counts read from the font: * A long run count could overflow to a negative value, and the next run painted bits before the start of the bitmap. This is the heap overflow of the issue. * A repeat count, or a run, larger than the rows left wrote past the end of the bitmap. * A truncated glyph never ended. Reject those counts, and stop at the end of the file. In Evince, test-mdvi-pk decodes crafted glyphs: without this change they overflow the heap (under AddressSanitizer) or hang. The 50363 glyphs of the 311 PK fonts generated by TeX Live on my machine still decode. The test is not included here. Reported by David Chen: https://gitlab.gnome.org/GNOME/evince/-/issues/2169 Taken from Evince commit d19fae674cbf0b85f4fe825f6d8e2dd3d3b3c598
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
These are fixes from Evince 48.5 (2026-11-16) for the DVI backend
(backend/dvi/mdvi-lib), which your code shares. Each commit is the
Evince commit as is, with a reference to it.
Two hunks needed only whitespace changes of context to apply.
The main one is a heap out-of-bounds write in the PK font decoder,
reported to Evince by David Chen:
https://gitlab.gnome.org/GNOME/evince/-/issues/2169
A long run count in a packed glyph overflows to a negative value and
the decoder writes before the start of the glyph bitmap; run and repeat
counts larger than the rows left write past its end. It is triggered by
opening a DVI document while a crafted PK font is in the font search
path, which includes the working directory. The reporter says it leads
to code execution; we reproduced the out-of-bounds write under
AddressSanitizer.
The other four are also out-of-bounds writes with lengths read from a
font file: the TFM/OFM font family, GF specials, VF packets, and a
truncated PK preamble.
We are requesting a CVE for #2169 from Red Hat's CNA, and will tell
them that this project is affected too. Please tell us if you have
requested one already, to avoid duplicates. We will request a CVE for
the other four as well.
Tested: Evince's test for the PK decoder (test-mdvi-pk), built against
this mdvi-lib under AddressSanitizer, overflows the heap on master and
passes with this branch; so does its truncated preamble case. The DVI
backend builds without warnings. The tests are not included, since
this project has no test setup for the backend.