LibPDF: Tolerate palettes that are one byte too long

Fixes these errors from `Meta/test_pdf.py path/to/0000`, with
0000 being 0000.zip from the PDF/A corpus in unzipped:

    Malformed PDF file: Indexed color space lookup table doesn't
                        match size, in 4 files, on 8 pages, 73 times
      path/to/0000/0000206.pdf 2 4 (2x) 5 (3x) 6 (4x)
      path/to/0000/0000364.pdf 5 6
      path/to/0000/0000918.pdf 5
      path/to/0000/0000683.pdf 8
This commit is contained in:
Nico Weber 2023-12-06 19:11:06 -05:00 committed by Sam Atkins
parent 832a065687
commit 43cd3d7dbd

View file

@ -669,8 +669,15 @@ PDFErrorOr<NonnullRefPtr<ColorSpace>> IndexedColorSpace::create(Document* docume
return Error { Error::Type::MalformedPDF, "Indexed color space expects stream or string for third arg" };
}
if (static_cast<int>(lookup.size()) != (hival + 1) * base->number_of_components())
size_t needed_size = (hival + 1) * base->number_of_components();
if (lookup.size() - 1 == needed_size) {
// FIXME: Could do this if lookup.size() > needed_size generally, but so far I've only seen files that had one byte too much.
lookup.resize(needed_size);
}
if (lookup.size() != needed_size) {
dbgln("lookup size {} doesn't match hival {} and base components {}", lookup.size(), hival, base->number_of_components());
return Error { Error::Type::MalformedPDF, "Indexed color space lookup table doesn't match size" };
}
auto color_space = adopt_ref(*new IndexedColorSpace(move(base)));
color_space->m_hival = hival;