pdf-rs / pdf

Rust library to read, manipulate and write PDF files.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Test for length of encryption key does not work for my PDF

RudolfVonKrugstein opened this issue · comments

commented

Hello,

I have a PDF, which I unfortantly cannot share because it contains private data.
The PDF is encrypted, but not with a password but a contained encryption key (don't know if this aspect is important).

In this line https://github.com/pdf-rs/pdf/blob/master/pdf/src/crypt.rs#L322 loading my pdf fails because key_bits is 1024.

I tried to compare the code to the pdf specs, but I habe to admit it did not make sense to me.

I can say that for my pdf the following is true at that line:

v==4;
default.lenght==Some(128);
default.method=="AESv2";

If I change the test to:

if key_bits < 1 || key_bits > 1024 {
        bail!("key bits must be between 1 and 1024");
}

My PDF loads successfully and as far as I can tell also contains the correct data.

I can create a pull request for this, but I am unsure because I do not really know what is going on.

Does someone know more?
I know without me providing the PDF, its a bit diffult, but I am happy to extract any additonal data from it, if it helps or do some more investigation if you tell me in which direction to look :).

Thank you for your time and knowledge!

commented

Seem to be fixed in 59f4a3e

"Fixed". More like i just removed the check and switched to a vec instead of a fixed size array.
The whole encryption is a mess.