mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 23:50:19 +00:00
LibPDF: Be more cautious of errors when looking for linearization dict
We would previously assume that, following the header, there must be a valid PDF object that could be a linearization dict. However, if the file is not linearized, this is not necessarily true. We now try to detect if there even is an object, and don't treat parsing errors as fatal.
This commit is contained in:
parent
6c0f7d83bb
commit
93062e2b78
Notes:
sideshowbarker
2024-07-17 06:46:15 +09:00
Author: https://github.com/janso3 Commit: https://github.com/SerenityOS/serenity/commit/93062e2b78 Pull-request: https://github.com/SerenityOS/serenity/pull/17975
1 changed files with 15 additions and 2 deletions
|
@ -111,8 +111,21 @@ PDFErrorOr<void> DocumentParser::parse_header()
|
|||
|
||||
PDFErrorOr<DocumentParser::LinearizationResult> DocumentParser::initialize_linearization_dict()
|
||||
{
|
||||
// parse_header() is called immediately before this, so we are at the right location
|
||||
auto indirect_value = Value(*TRY(parse_indirect_value()));
|
||||
// parse_header() is called immediately before this, so we are at the right location.
|
||||
// There may not actually be a linearization dict, or even a valid PDF object here.
|
||||
// If that is the case, this file may be completely valid but not linearized.
|
||||
|
||||
// If there is indeed a linearization dict, there should be an object number here.
|
||||
if (!m_reader.matches_number())
|
||||
return LinearizationResult::NotLinearized;
|
||||
|
||||
// At this point, we still don't know for sure if we are dealing with a valid object.
|
||||
auto indirect_value_or_error = parse_indirect_value();
|
||||
if (indirect_value_or_error.is_error())
|
||||
return LinearizationResult::NotLinearized;
|
||||
|
||||
auto indirect_value = indirect_value_or_error.value();
|
||||
|
||||
auto dict_value = TRY(m_document->resolve(indirect_value));
|
||||
if (!dict_value.has<NonnullRefPtr<Object>>())
|
||||
return error("Expected linearization object to be a dictionary");
|
||||
|
|
Loading…
Reference in a new issue