LibPDF/CFF: Fix off-by-one when reading internal encoding

We use `i - 1` to index these arrays, so that's what we should use
for the bounds check as well.
This commit is contained in:
Nico Weber 2024-02-19 21:43:58 -05:00 committed by Sam Atkins
commit 4705d38fa7
Notes: sideshowbarker 2024-07-17 04:32:07 +09:00

View file

@ -279,8 +279,9 @@ PDFErrorOr<NonnullRefPtr<CFF>> CFF::create(ReadonlyBytes const& cff_bytes, RefPt
encoding->set(0, ".notdef");
continue;
}
if (i >= encoding_codes.size() || i >= charset_names.size())
if (i - 1 >= encoding_codes.size() || i - 1 >= charset_names.size()) {
break;
}
auto code = encoding_codes[i - 1];
auto char_name = charset_names[i - 1];
encoding->set(code, char_name);