gettalong / hexapdf

Versatile PDF creation and manipulation for Ruby
https://hexapdf.gettalong.org
Other
1.21k stars 69 forks source link

AES initialization vector length must be 128 bit (HexaPDF::EncryptionError) #237

Closed earthlingworks closed 1 year ago

earthlingworks commented 1 year ago

Hello, we have a new error, a bit weird, on a PDF.

Error: AES initialization vector length must be 128 bit (HexaPDF::EncryptionError)

Context is we're a couple of PDFs and making them into a single PDF. I'll send the PDF through email.

Script to reproduce (which basically just takes the same PDF imports it into a single file):

require 'hexapdf'
​
original = HexaPDF::Document.open(ARGV[0])
path = 'output.pdf'
path2 = 'output2.pdf'
original.write(path, validate: false, optimize: true)
​
target = HexaPDF::Document.new
source = HexaPDF::Document.open(path)
​
importer = HexaPDF::Importer.for(target)
​
source.pages.each { |page| target.pages << importer.import(page, source: source) }
​
target.write(path2, validate: false, optimize: true)
gettalong commented 1 year ago

Thanks for the report - did you send the file?

Also, this may be related to #233.

earthlingworks commented 1 year ago

Oops..completely forgot, thanks will send now!

gettalong commented 1 year ago

Thanks for the file!

The problem here is that an AES encrypted string or stream should at least contain the initialization vector having 16 bytes and the padding. But the file has streams that are just empty.

To fix this HexaPDF will now check for empty string/streams which fixes the problem.

earthlingworks commented 1 year ago

Great, thank you!