ladybird/Userland
Nico Weber 11bee7a075 LibPDF: Don't crash on fixed-width type 1 fonts that use /MissingWidth
Type 1 fonts usually have a m_font_program and no m_font -- they only
have m_font if we're using a replacement font for the fonts that
were built-in to PDFs before Acrobat 4.0 (and must still work to
show existing files).

However, SimpleFont::get_glyph_width() used to always return a
float, which in Type1Font was only implemented if m_font was set.

Per spec, we're supposed to just use /MissingWidth for fonts that
are missing an entry in the descriptor's /Width array. However, for
built-in fonts, no explicit /Width array is needed (PDF 1.7 spec,
Appendix H.3, 5.5.1). So if we just always use /MissingWidth,
then PDFs that use a built-in font draw all their text on top
of each other (e.g. 000333.pdf from stillhq.com-pdfdb).

So change get_glyph_width() to return Optional<float>, return
it only in Type1Font if m_font is set, and use MissingWidth
if it isn't set.

That way, replacement fonts still return a width, and real
fonts that are supposed to have /Width and use /MissingWidth
for missing entries do what they're supposed to too, instead
of crashing.

From 20 (6%) to 16 (5%) crashes on the 300 first PDFs, and from
39 (7.8%) to 31 (6.2%) on the 500-random PDFs test.
2023-10-23 09:33:03 -04:00
..
Applets LibGfx: Remove indexed palette formats from Bitmap and Painter 2023-10-12 07:39:05 +02:00
Applications AK: Remove rarely used ExtraMathConstants.h 2023-10-23 12:04:51 +01:00
BuggieBox checksum: Add support for BLAKE2b 2023-09-17 16:49:35 +03:30
Demos Userland: Use non-fallible EventReceiver::add() where possible 2023-09-25 10:58:31 +02:00
DevTools AK+Everywhere: Remove the null state of DeprecatedString 2023-10-13 18:33:21 +03:30
DynamicLoader DynamicLoader: Add an option to explicitly run an ELF executable binary 2023-10-16 12:09:04 +02:00
Games GameOfLife: Allow pressing escape to clear the selected pattern 2023-10-07 11:36:57 +02:00
Libraries LibPDF: Don't crash on fixed-width type 1 fonts that use /MissingWidth 2023-10-23 09:33:03 -04:00
Services LibWeb: Remove ClearRect command in RecordingPainter 2023-10-21 18:50:28 +02:00
Shell Shell: Don't try to cast NonnullRefPtrs when priting debug output 2023-10-22 02:02:35 +03:30
Utilities du: Add -x option to not traverse directories across filesystems 2023-10-19 14:41:09 +02:00
CMakeLists.txt Userland: Add the BuggieBox program 2022-11-26 12:41:47 -07:00