mirror of
https://github.com/SerenityOS/serenity.git
synced 2025-01-24 18:32:28 -05:00
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:
parent
832a065687
commit
43cd3d7dbd
1 changed files with 8 additions and 1 deletions
|
@ -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;
|
||||
|
|
Loading…
Add table
Reference in a new issue