bcgit / bc-java

Bouncy Castle Java Distribution (Mirror)
https://www.bouncycastle.org/java.html
MIT License
2.33k stars 1.14k forks source link

`literal data truncated in header` exception #1906

Closed Arthurm1 closed 1 day ago

Arthurm1 commented 1 week ago

Since upgrading to 1.79 I get a literal data truncated in header exception when reading LiteralDataPacket.

I'm not sure but I think this might be down to the changes in reading the modification time.

Before 1.79 the code was...

(((long)in.read() << 24) | (in.read() << 16) | (in.read() << 8) | in.read()) * 1000L

which would cope with a maximum date of new Date(Long.MAX_VALUE) // Sun Aug 17 07:12:55 GMT 292278994

Now it is...

(long) ((in.read() << 24) | (in.read() << 16) | (in.read() << 8) | in.read()) * 1000L

which would cope with a maximum date of new Date(Integer.MAX_VALUE * 1000L) // Tue Jan 19 03:14:07 GMT 2038

I was using random data 1 Jan 2074 for testing and hit this as a negative date throws the exception.

ligefeiBouncycastle commented 1 day ago

Fixed in https://github.com/bcgit/bc-java/commit/8902307a09adc76195d7e3985a4d22660bd102c5