From 8922574133d59547ed65cc8ceee272ef3a7b4a3c Mon Sep 17 00:00:00 2001 From: Nico Weber Date: Fri, 20 Oct 2023 23:36:56 -0400 Subject: [PATCH] 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/ --- Userland/Libraries/LibPDF/Document.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/Userland/Libraries/LibPDF/Document.cpp b/Userland/Libraries/LibPDF/Document.cpp index 62989271e4..3e4e7a0115 100644 --- a/Userland/Libraries/LibPDF/Document.cpp +++ b/Userland/Libraries/LibPDF/Document.cpp @@ -451,7 +451,15 @@ PDFErrorOr 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 page_number; + if (page_ref.has()) + page_number = page_ref.get(); + else + page_number = page_number_by_index_ref.get(page_ref.as_ref_index()); + + return Destination { type, page_number, parameters }; } PDFErrorOr>> Document::get_inheritable_object(DeprecatedFlyString const& name, NonnullRefPtr object)