diff --git a/Userland/Libraries/LibPDF/Document.h b/Userland/Libraries/LibPDF/Document.h index 85a64baa00..bbb7bc164f 100644 --- a/Userland/Libraries/LibPDF/Document.h +++ b/Userland/Libraries/LibPDF/Document.h @@ -119,6 +119,11 @@ public: return cast_to(TRY(resolve(value))); } + /// Whether this Document is reasdy to resolve references, which is usually + /// true, except just before the XRef table is parsed (and while the linearization + /// dict is being read). + bool can_resolve_refefences() { return m_parser->can_resolve_references(); } + private: explicit Document(NonnullRefPtr const& parser); diff --git a/Userland/Libraries/LibPDF/DocumentParser.h b/Userland/Libraries/LibPDF/DocumentParser.h index 590bca7f1a..0f58821a73 100644 --- a/Userland/Libraries/LibPDF/DocumentParser.h +++ b/Userland/Libraries/LibPDF/DocumentParser.h @@ -25,6 +25,8 @@ public: // Parses the header and initializes the xref table and trailer PDFErrorOr initialize(); + bool can_resolve_references() { return m_xref_table; }; + PDFErrorOr parse_object_with_index(u32 index); // Specialized version of parse_dict which aborts early if the dict being parsed diff --git a/Userland/Libraries/LibPDF/Parser.cpp b/Userland/Libraries/LibPDF/Parser.cpp index a51f0f8e53..374230a49b 100644 --- a/Userland/Libraries/LibPDF/Parser.cpp +++ b/Userland/Libraries/LibPDF/Parser.cpp @@ -446,7 +446,7 @@ PDFErrorOr> Parser::parse_stream(NonnullRefPtrget(CommonNames::Length); - if (maybe_length.has_value() && (!maybe_length->has())) { + if (maybe_length.has_value() && m_document->can_resolve_refefences()) { // The PDF writer has kindly provided us with the direct length of the stream m_reader.save(); auto length = TRY(m_document->resolve_to(maybe_length.value())); @@ -457,17 +457,13 @@ PDFErrorOr> Parser::parse_stream(NonnullRefPtr