Apache POI 5.2.2 fails reading a .xls File (Excel 2003) when calling
WorkbookFactory.create(inputStream)
with the following StackTrace:
java.lang.ArrayIndexOutOfBoundsException: Index -2 out of bounds for length 30182
at org.apache.poi.poifs.filesystem.BlockStore$ChainLoopDetector.claim(BlockStore.java:108)
at org.apache.poi.poifs.filesystem.POIFSFileSystem.readCoreContents(POIFSFileSystem.java:406)
at org.apache.poi.poifs.filesystem.POIFSFileSystem.<init>(POIFSFileSystem.java:361)
at org.apache.poi.ss.usermodel.WorkbookFactory.create(WorkbookFactory.java:231)
at org.apache.poi.ss.usermodel.WorkbookFactory.create(WorkbookFactory.java:185)
I am sorry to not be able to provide the exact file, since it contains sensitive data, which makes it hard to reproduce.
After opening and saving the file with Excel, the file can be read with POI without any issue. The file was created with POI (currently finding out how and with what version (other department)). I saw the issue on other platforms, it exists since a long time, but I could not find it on Stackoverflow.com. I hope somebody can provide a file with non-sensitive data with the same issue.
// Claiming an existing block, ensure there's no loop
if(used_blocks[offset]) {
throw new IllegalStateException(
"Potential loop detected - Block " + offset +
" was already claimed but was just requested again"
);
}
The offset is not existing in used_blocks array.