Bug 39903

Summary: OutOfMemoryError reading Excel file when page count "lies"
Product: POI Reporter: Trejkaz (pen name) <trejkaz>
Component: HSSFAssignee: POI Developers List <dev>
Status: RESOLVED FIXED    
Severity: normal Keywords: PatchAvailable
Priority: P2    
Version: 3.0-dev   
Target Milestone: ---   
Hardware: Other   
OS: other   
Attachments: Patch to work around this issue

Description Trejkaz (pen name) 2006-06-27 01:12:08 UTC
A certain Excel document (generated by MS Excel itself) in our collection
claimed to have over 200 sheets, but in reality had only three valid sheets. 
This resulted in a tight loop in HSSFWorkbook around line 194.

Luckily the condition is easily detected and worked around.  Patch coming in a
moment after some sanity tests.
Comment 1 Trejkaz (pen name) 2006-06-27 01:15:17 UTC
Created attachment 18539 [details]
Patch to work around this issue
Comment 2 Trejkaz (pen name) 2006-06-27 01:18:49 UTC
No unit tests I'm afraid.  The document in question was confidential, and I'm
not sure how to reproduce bogus documents.  (Hex editor, perhaps?  Hmm.)
Comment 3 Yegor Kozlov 2007-04-19 10:53:43 UTC
Trejkaz,

Any chance to get a unit test for this? 
The fix looks quite harmless to me but applying it without a testcase is against
the rules. 

Regards,
Yegor
Comment 4 Trejkaz (pen name) 2007-04-19 20:31:31 UTC
I'm not sure how I would create the test document.
Comment 5 Yegor Kozlov 2007-04-20 03:56:21 UTC
Trejkaz,

No patch is required.
It turns out that the code you are suggesting is already present in the 
HSSFWorkbook constructor:

            recOffset = sheet.getEofLoc()+1;
            if (recOffset == 1)
            {
                break;
            }

Could you confirm that there are no problems with the latest 3.0 RC2 jar? 

Yegor
Comment 6 Josh Micich 2008-05-23 00:42:51 UTC
The patch was done in svn r529196 due to bug 41223.

There is an existing junit that fails with OOME when this patch is rolled back:
TestHSSFSheet.testGroupRowsExisting() 
This was not part of the patch for that bug.

I modified that junit to annotate this bug's failure (svn r659462).