mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 16:07:47 +00:00
LibPDF: Don't treat a broken document header as a fatal error
As the current goal is to make our best effort loading documents, we might as well ignore a broken header and power through, giving the user a warning.
This commit is contained in:
parent
f66de973ff
commit
6c0f7d83bb
1 changed files with 9 additions and 5 deletions
|
@ -23,7 +23,15 @@ DocumentParser::DocumentParser(Document* document, ReadonlyBytes bytes)
|
|||
|
||||
PDFErrorOr<void> DocumentParser::initialize()
|
||||
{
|
||||
TRY(parse_header());
|
||||
m_reader.set_reading_forwards();
|
||||
if (m_reader.remaining() == 0)
|
||||
return error("Empty PDF document");
|
||||
|
||||
auto maybe_error = parse_header();
|
||||
if (maybe_error.is_error()) {
|
||||
warnln("{}", maybe_error.error().message());
|
||||
warnln("No valid PDF header detected, continuing anyway.");
|
||||
}
|
||||
|
||||
auto const linearization_result = TRY(initialize_linearization_dict());
|
||||
|
||||
|
@ -68,10 +76,6 @@ PDFErrorOr<Value> DocumentParser::parse_object_with_index(u32 index)
|
|||
PDFErrorOr<void> DocumentParser::parse_header()
|
||||
{
|
||||
// FIXME: Do something with the version?
|
||||
m_reader.set_reading_forwards();
|
||||
if (m_reader.remaining() == 0)
|
||||
return error("Empty PDF document");
|
||||
|
||||
m_reader.move_to(0);
|
||||
if (m_reader.remaining() < 8 || !m_reader.matches("%PDF-"))
|
||||
return error("Not a PDF document");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue