From f9c1d1138007d95efcda8592d11e524c8200a584 Mon Sep 17 00:00:00 2001 From: Matthew Olsson Date: Sun, 16 Jul 2023 03:44:56 -0700 Subject: [PATCH] LibPDF: Do not crash when linearized length is incorrect This is a perfectly valid situation, and in this case we should just parse a standard non-linearized xref table. --- Userland/Libraries/LibPDF/DocumentParser.cpp | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/Userland/Libraries/LibPDF/DocumentParser.cpp b/Userland/Libraries/LibPDF/DocumentParser.cpp index 3bf17f635c..04928e1568 100644 --- a/Userland/Libraries/LibPDF/DocumentParser.cpp +++ b/Userland/Libraries/LibPDF/DocumentParser.cpp @@ -43,16 +43,10 @@ PDFErrorOr DocumentParser::initialize() bool is_linearized = m_linearization_dictionary.has_value(); if (is_linearized) { - // The file may have been linearized at one point, but could have been updated afterwards, - // which means it is no longer a linearized PDF file. + // If the length given in the linearization dictionary is not equal to the length + // of the document, then this file has most likely been incrementally updated, and + // should no longer be treated as linearized. is_linearized = m_linearization_dictionary.value().length_of_file == m_reader.bytes().size(); - - if (!is_linearized) { - // FIXME: The file shouldn't be treated as linearized, yet the xref tables are still - // split. This might take some tweaking to ensure correct behavior, which can be - // implemented later. - TODO(); - } } if (is_linearized)