From 08381b20e0e2d42eb8ebddab0c9495bab85311ff Mon Sep 17 00:00:00 2001 From: Nico Weber Date: Tue, 20 Feb 2024 12:14:37 -0500 Subject: [PATCH] LibGfx/OpenType: Allow zero-sized table entries Kind of reverts #21675, but #21744 made that better 4 of my 1000 test PDFs complained "Invalid table offset or length in font" before. For example, in 0000203.pdf, these tags had length 0: 'cvt ', 'fpgm', 'prep', 'name', 'OS/2'. (Generally it's tables that aren't needed for rendering PDFs, and the PDF writer figured it's easier to zero out these tables instead of omitting them altogether for some reason.) Increases number of PDFs that render without diagnostics from 765 to 767. --- Userland/Libraries/LibGfx/Font/OpenType/Font.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Userland/Libraries/LibGfx/Font/OpenType/Font.cpp b/Userland/Libraries/LibGfx/Font/OpenType/Font.cpp index b4aac6ae17..4ab5747d9b 100644 --- a/Userland/Libraries/LibGfx/Font/OpenType/Font.cpp +++ b/Userland/Libraries/LibGfx/Font/OpenType/Font.cpp @@ -210,7 +210,7 @@ ErrorOr> Font::try_load_from_offset(ReadonlyBytes buffer, u3 for (auto i = 0; i < table_directory.num_tables; i++) { auto& table_record = *TRY(stream.read_in_place()); - if (table_record.length == 0 || Checked::addition_would_overflow(static_cast(table_record.offset), static_cast(table_record.length))) + if (Checked::addition_would_overflow(static_cast(table_record.offset), static_cast(table_record.length))) return Error::from_string_literal("Invalid table offset or length in font"); if (buffer.size() < table_record.offset + table_record.length)