1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 18:07:34 +00:00

LibPDF: Fix assertion when destination page is an index

This isn't correct per spec, but it happens in practice, e.g.
0000847.pdf, 0000327.pdf, 0000124.pdf from 0000.zip from
https://pdfa.org/new-large-scale-pdf-corpus-now-publicly-available/
This commit is contained in:
Nico Weber 2023-10-20 23:36:56 -04:00 committed by Andreas Kling
parent fbd00d9c8e
commit 8922574133

View file

@ -451,7 +451,15 @@ PDFErrorOr<Destination> Document::create_destination_from_parameters(NonnullRefP
VERIFY_NOT_REACHED();
}
return Destination { type, page_number_by_index_ref.get(page_ref.as_ref_index()), parameters };
// The spec requires page_ref to be an indirect reference to a page object,
// but in practice it's sometimes a page index.
Optional<u32> page_number;
if (page_ref.has<int>())
page_number = page_ref.get<int>();
else
page_number = page_number_by_index_ref.get(page_ref.as_ref_index());
return Destination { type, page_number, parameters };
}
PDFErrorOr<Optional<NonnullRefPtr<Object>>> Document::get_inheritable_object(DeprecatedFlyString const& name, NonnullRefPtr<DictObject> object)