Skip to content

Commit

Permalink
Fix Signature#signed_data to work for invalid offsets
Browse files Browse the repository at this point in the history
  • Loading branch information
gettalong committed Sep 14, 2024
1 parent b6dcbc8 commit a63f5bc
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
* [HexaPDF::Type::AcroForm::Form] text-like field creation methods to always set
a default appearance string

### Fixed

* [HexaPDF::DigitalSignature::Signature#signed_data] to work for invalid offsets


## 0.47.0 - 2024-09-07

Expand Down
2 changes: 1 addition & 1 deletion lib/hexapdf/digital_signature/signature.rb
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ def signed_data
data = ''.b
self[:ByteRange]&.each_slice(2) do |offset, length|
io.pos = offset
data << io.read(length)
data << io.read(length).to_s
end
data
end
Expand Down
7 changes: 7 additions & 0 deletions test/hexapdf/digital_signature/test_signature.rb
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,13 @@
assert_equal((MINIMAL_PDF[0, 400] << MINIMAL_PDF[500, 333]).b, @sig.signed_data)
end

it "works for invalid offsets" do
doc = HexaPDF::Document.new(io: StringIO.new(MINIMAL_PDF))
@sig.document = doc
@sig[:ByteRange] = [0, 400, 9000, 333]
assert_equal(MINIMAL_PDF[0, 400], @sig.signed_data)
end

it "fails if the document isn't associated with an existing PDF file" do
assert_raises(HexaPDF::Error) { @sig.signed_data }
end
Expand Down

0 comments on commit a63f5bc

Please sign in to comment.