Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RFC] resolve a recursion bug in ObjectHash#deref! #195

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions lib/pdf/reader/object_hash.rb
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,6 @@ def deref!(key)
hash[k] = deref!(value)
end
}
when PDF::Reader::Stream
object.hash = deref!(object.hash)
object
when Array
object.map { |value| deref!(value) }
else
Expand Down
Binary file added spec/data/form_xobject_recursive.pdf
Binary file not shown.
10 changes: 10 additions & 0 deletions spec/integration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,16 @@
end
end

context "PDF that has a Form XObjects that references itself" do
let(:filename) { pdf_spec_file("form_xobject_recursive") }

it "extracts text correctly" do
PDF::Reader.open(filename) do |reader|
expect(reader.page(1).text).to include("this form XObject contains a reference to itself")
end
end
end

context "PDF that uses multiple content streams for a single page" do
let(:filename) { pdf_spec_file("split_params_and_operator") }

Expand Down
3 changes: 3 additions & 0 deletions spec/integrity.yml
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,9 @@ data/form_xobject.pdf:
data/form_xobject_more.pdf:
:bytes: 22055
:md5: 1fcbd5a3f7429dd224871d8d9d7830a7
data/form_xobject_recursive.pdf:
:bytes: 1454
:md5: 24cbbe4f91c23b37f9a1ddac81bd3a39
data/hard_lock_under_osx.pdf:
:bytes: 4545
:md5: 365e2076036b5e2445d1dcde13d6dbb6
Expand Down
5 changes: 0 additions & 5 deletions spec/object_hash_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,6 @@
PDF::Reader::Stream
end

it "recursively dereferences references within stream hashes" do
font_file = hash.deref! PDF::Reader::Reference.new(15, 0)
expect(font_file.hash[:Length]).to eq 2103
end

it "recursively dereferences references within arrays" do
font = hash.deref! PDF::Reader::Reference.new(19, 0)
expect(font[:DescendantFonts][0][:Subtype]).to eq :CIDFontType0
Expand Down