Переглянути джерело

LibPDF: Tolerate whitespace after `xref` and `startxref`

The spec isn't super clear on if this is allowed:

"""Each cross-reference section shall begin with a line containing the
keyword xref. Following this line..."""

"""The two preceding lines shall contain, one per line and in order, the
keyword startxref and..."""

It kind of sounds like anything goes on both lines as long as they
contain `xref` and `startxref`.

In practice, both seem to always occur at the start of their line,
but in 0000780.pdf (and nowhere else), there's one space after each
keyword before the following linebreak, and this makes that file load.
Nico Weber 1 рік тому
батько
коміт
1b45c3e127
1 змінених файлів з 3 додано та 0 видалено
  1. 3 0
      Userland/Libraries/LibPDF/DocumentParser.cpp

+ 3 - 0
Userland/Libraries/LibPDF/DocumentParser.cpp

@@ -481,6 +481,7 @@ PDFErrorOr<NonnullRefPtr<XRefTable>> DocumentParser::parse_xref_table()
     }
     }
 
 
     m_reader.move_by(4);
     m_reader.move_by(4);
+    m_reader.consume_non_eol_whitespace();
     if (!m_reader.consume_eol())
     if (!m_reader.consume_eol())
         return error("Expected newline after \"xref\"");
         return error("Expected newline after \"xref\"");
 
 
@@ -741,6 +742,8 @@ bool DocumentParser::navigate_to_after_startxref()
         auto offset = m_reader.offset() + 1;
         auto offset = m_reader.offset() + 1;
 
 
         m_reader.consume_eol();
         m_reader.consume_eol();
+        m_reader.consume_whitespace();
+
         if (!m_reader.matches("startxref"))
         if (!m_reader.matches("startxref"))
             continue;
             continue;