Bug 39903 - OutOfMemoryError reading Excel file when page count "lies"
Summary: OutOfMemoryError reading Excel file when page count "lies"
Alias: None
Product: POI
Classification: Unclassified
Component: HSSF (show other bugs)
Version: 3.0-dev
Hardware: Other other
: P2 normal (vote)
Target Milestone: ---
Assignee: POI Developers List
Keywords: PatchAvailable
Depends on:
Reported: 2006-06-27 01:12 UTC by Trejkaz (pen name)
Modified: 2008-05-23 00:42 UTC (History)
0 users

Patch to work around this issue (623 bytes, patch)
2006-06-27 01:15 UTC, Trejkaz (pen name)
Details | Diff

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

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. 

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

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)

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

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:
This was not part of the patch for that bug.

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