Bug 41357 - OutOfMemoryException and Infinite Loop in HSLFSlideShow
Summary: OutOfMemoryException and Infinite Loop in HSLFSlideShow
Alias: None
Product: POI
Classification: Unclassified
Component: HSLF (show other bugs)
Version: 3.0-dev
Hardware: All other
: P2 normal (vote)
Target Milestone: ---
Assignee: POI Developers List
Depends on:
Reported: 2007-01-12 05:02 UTC by Raiko Eckstein
Modified: 2007-01-15 08:41 UTC (History)
0 users

The ppt presentation (161.50 KB, application/octet-stream)
2007-01-12 10:17 UTC, Raiko Eckstein

Note You need to log in before you can comment on or make changes to this bug.
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. 

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)