0

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.

Bernhard Kern
  • 208
  • 2
  • 10
  • How are you receiving the file? [FTP transfer issue here](https://stackoverflow.com/questions/37652908/apache-poi-excel-file-reading-potential-loop-detected-block-0-was-already-cl). [Also this](https://stackoverflow.com/questions/68073203/what-does-java-lang-arrayindexoutofboundsexception-index-2-out-of-bounds-for-l) – XtremeBaumer Apr 22 '22 at 06:17
  • Thx for the link, seems to be exactly the same issue. And the file could also not be provided. Thats bad, but I do not know how to reproduce the issue without exactly this file. The file is sent with an http interface, so no ftp. We receive many of those files every day from the same system. It is very specific to this file. We could reproduce it on another stage (qa), so it is no network issue or delivery issue. – Bernhard Kern Apr 22 '22 at 06:37
  • The only option for you is to fix the file creation process. Perhaps upgrade to .xlsx even. Or depending on what the file does, a CSV might be even better – XtremeBaumer Apr 22 '22 at 06:48
  • Yes, I have the same opinion with .csv (or .xlsx), but we get the file delivered by another department, we cannot influence it a lot. – Bernhard Kern Apr 22 '22 at 07:34
  • 2
    Well, we can't help you here in any way. If you really need to process the file, then they must fix it. There is no way around it. Unless you want to manually open -> save each file – XtremeBaumer Apr 22 '22 at 07:41

0 Answers0