mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 13:07:47 +00:00
LibPDF: Keep track of the current object index/generation while Parsing
This information is required to decrypt encrypted strings/streams.
This commit is contained in:
parent
5b316462b2
commit
a8de9cf541
2 changed files with 20 additions and 4 deletions
|
@ -613,20 +613,26 @@ PDFErrorOr<Value> Parser::parse_possible_indirect_value_or_ref()
|
||||||
|
|
||||||
if (m_reader.matches("obj")) {
|
if (m_reader.matches("obj")) {
|
||||||
m_reader.discard();
|
m_reader.discard();
|
||||||
return TRY(parse_indirect_value(first_number.get<int>(), second_number.value().get<int>()));
|
auto index = first_number.get<int>();
|
||||||
|
auto generation = second_number.value().get<int>();
|
||||||
|
VERIFY(index >= 0);
|
||||||
|
VERIFY(generation >= 0);
|
||||||
|
return TRY(parse_indirect_value(index, generation));
|
||||||
}
|
}
|
||||||
|
|
||||||
m_reader.load();
|
m_reader.load();
|
||||||
return first_number;
|
return first_number;
|
||||||
}
|
}
|
||||||
|
|
||||||
PDFErrorOr<NonnullRefPtr<IndirectValue>> Parser::parse_indirect_value(int index, int generation)
|
PDFErrorOr<NonnullRefPtr<IndirectValue>> Parser::parse_indirect_value(u32 index, u32 generation)
|
||||||
{
|
{
|
||||||
if (!m_reader.matches("obj"))
|
if (!m_reader.matches("obj"))
|
||||||
return error("Expected \"obj\" at beginning of indirect value");
|
return error("Expected \"obj\" at beginning of indirect value");
|
||||||
m_reader.move_by(3);
|
m_reader.move_by(3);
|
||||||
if (matches_eol())
|
if (matches_eol())
|
||||||
consume_eol();
|
consume_eol();
|
||||||
|
|
||||||
|
push_reference({ index, generation });
|
||||||
auto value = TRY(parse_value());
|
auto value = TRY(parse_value());
|
||||||
if (!m_reader.matches("endobj"))
|
if (!m_reader.matches("endobj"))
|
||||||
return error("Expected \"endobj\" at end of indirect value");
|
return error("Expected \"endobj\" at end of indirect value");
|
||||||
|
@ -634,6 +640,8 @@ PDFErrorOr<NonnullRefPtr<IndirectValue>> Parser::parse_indirect_value(int index,
|
||||||
consume(6);
|
consume(6);
|
||||||
consume_whitespace();
|
consume_whitespace();
|
||||||
|
|
||||||
|
pop_reference();
|
||||||
|
|
||||||
return make_object<IndirectValue>(index, generation, value);
|
return make_object<IndirectValue>(index, generation, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -641,7 +649,11 @@ PDFErrorOr<NonnullRefPtr<IndirectValue>> Parser::parse_indirect_value()
|
||||||
{
|
{
|
||||||
auto first_number = TRY(parse_number());
|
auto first_number = TRY(parse_number());
|
||||||
auto second_number = TRY(parse_number());
|
auto second_number = TRY(parse_number());
|
||||||
return parse_indirect_value(first_number.get<int>(), second_number.get<int>());
|
auto index = first_number.get<int>();
|
||||||
|
auto generation = second_number.get<int>();
|
||||||
|
VERIFY(index >= 0);
|
||||||
|
VERIFY(generation >= 0);
|
||||||
|
return parse_indirect_value(index, generation);
|
||||||
}
|
}
|
||||||
|
|
||||||
PDFErrorOr<Value> Parser::parse_number()
|
PDFErrorOr<Value> Parser::parse_number()
|
||||||
|
|
|
@ -104,7 +104,7 @@ private:
|
||||||
|
|
||||||
PDFErrorOr<Value> parse_value();
|
PDFErrorOr<Value> parse_value();
|
||||||
PDFErrorOr<Value> parse_possible_indirect_value_or_ref();
|
PDFErrorOr<Value> parse_possible_indirect_value_or_ref();
|
||||||
PDFErrorOr<NonnullRefPtr<IndirectValue>> parse_indirect_value(int index, int generation);
|
PDFErrorOr<NonnullRefPtr<IndirectValue>> parse_indirect_value(u32 index, u32 generation);
|
||||||
PDFErrorOr<NonnullRefPtr<IndirectValue>> parse_indirect_value();
|
PDFErrorOr<NonnullRefPtr<IndirectValue>> parse_indirect_value();
|
||||||
PDFErrorOr<Value> parse_number();
|
PDFErrorOr<Value> parse_number();
|
||||||
PDFErrorOr<NonnullRefPtr<NameObject>> parse_name();
|
PDFErrorOr<NonnullRefPtr<NameObject>> parse_name();
|
||||||
|
@ -117,6 +117,9 @@ private:
|
||||||
|
|
||||||
PDFErrorOr<Vector<Command>> parse_graphics_commands();
|
PDFErrorOr<Vector<Command>> parse_graphics_commands();
|
||||||
|
|
||||||
|
void push_reference(Reference const& ref) { m_current_reference_stack.append(ref); }
|
||||||
|
void pop_reference() { m_current_reference_stack.take_last(); }
|
||||||
|
|
||||||
bool matches_eol() const;
|
bool matches_eol() const;
|
||||||
bool matches_whitespace() const;
|
bool matches_whitespace() const;
|
||||||
bool matches_number() const;
|
bool matches_number() const;
|
||||||
|
@ -142,6 +145,7 @@ private:
|
||||||
RefPtr<XRefTable> m_xref_table;
|
RefPtr<XRefTable> m_xref_table;
|
||||||
RefPtr<DictObject> m_trailer;
|
RefPtr<DictObject> m_trailer;
|
||||||
Optional<LinearizationDictionary> m_linearization_dictionary;
|
Optional<LinearizationDictionary> m_linearization_dictionary;
|
||||||
|
Vector<Reference> m_current_reference_stack;
|
||||||
};
|
};
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue