Bug 41357

Summary: OutOfMemoryException and Infinite Loop in HSLFSlideShow
Product: POI Reporter: Raiko Eckstein <asf>
Component: HSLFAssignee: POI Developers List <dev>
Status: RESOLVED FIXED    
Severity: normal    
Priority: P2    
Version: 3.0-dev   
Target Milestone: ---   
Hardware: All   
OS: other   
Attachments: The ppt presentation

Description Raiko Eckstein 2007-01-12 05:02:56 UTC
The HLSFSlideShow.readPictures() method can result in an infinite loop. 

When trying to instantiate an PowerPointExtractor with
poi-scratchpad-3.0-alpha3-20061212.jar the following exception was raised.

Problem reading picture: java.lang.IllegalArgumentException: Unsupported picture
type: -61464
You document will probably become corrupted if you save it!

While debugging i noticed that POI was trying to read pictures out of a PPT
presentation, unfortunately at least one picture was of size 0 (don't know why).
   That made the method HSLFSlideShow.readPictures() ran into an infinite loop
at line 283 at
            pos += imgsize;
because imgsize was zero.
Comment 1 Yegor Kozlov 2007-01-12 05:34:08 UTC
Could you attach the ppt file? Without it it is impossible to debug the problem. 

Yegor
Comment 2 Nick Burch 2007-01-12 06:21:11 UTC
It shouldn't be able to get into an infinite loop, as the code always winds on
by the size of the header block (8 bytes)

I've added a check to ensure the img size is positive, since a negative one
could lead to an infinite loop. 

Can you re-open the bug if this doesn't help, and upload the problem document?
Comment 3 Raiko Eckstein 2007-01-12 10:17:00 UTC
Created attachment 19401 [details]
The ppt presentation

Unfortunately that change didn't help. I attached the problematic ppt file.
Comment 4 Nick Burch 2007-01-15 08:41:14 UTC
Ah, I was being bitten by java's garbage collection not playing nicely with
loops of the kind we're using

I've shifted the byte array creation until after we've decided we have a real
picture. That fixes the memory exception for me. (I've also added a test to the
suite, using your sample doc, to check it stays fixed)