Bug 61381

Summary: PushbackInputStreams passed to ZipHelper may not hold 8 bytes
Product: POI Reporter: Kenzie Togami <ket1999>
Component: OPCAssignee: POI Developers List <dev>
Status: RESOLVED FIXED    
Severity: normal CC: ket1999
Priority: P2    
Version: 3.17-dev   
Target Milestone: ---   
Hardware: All   
OS: All   
Attachments: Example

Description Kenzie Togami 2017-08-04 01:55:33 UTC
Created attachment 35200 [details]
Example

ZipHelper tries to be efficient when checking the header by reusing PushbackInputStreams that are given as input, but these streams may not hold the 8 bytes that are pushed back, and can cause an exception.

Testable example is attached.

Workaround: Wrap InputStreams in BufferedInputStream before passing them to anything that uses ZipHelper.

Solutions:
- always create a new PushbackInputStream
- stop using PushbackInputStream and switch to mark/reset + BufferedInputStream
Comment 1 Andreas Beeker 2017-08-06 17:20:16 UTC
Thanks for pointing this out.

I'm currently replacing the PushbackInputStream calls (option 2) and refactor the file magic checks in one spot.
Comment 2 Andreas Beeker 2017-08-11 20:49:23 UTC
patched via r1804854