Hi, I will add a zip file containing a test case and the xlsx file. The password protected xlsx was generated using the extenxls jar and I suspect that it creates metadata that is not 100% valid. If I resave the xlsx using Excel 2011, the file can be decrypted ok with poi (v3.10.1). Would it be possible for someone to look at why the IndexOutOfBoundsException is happening and if the code could workaround from the underlying xlsx issue? Regards, PJ java.lang.ArrayIndexOutOfBoundsException: 12 at org.apache.poi.poifs.storage.DocumentBlock.getDataInputBlock(DocumentBlock.java:177) at org.apache.poi.poifs.filesystem.POIFSDocument.getDataInputBlock(POIFSDocument.java:284) at org.apache.poi.poifs.filesystem.ODocumentInputStream.getDataInputBlock(ODocumentInputStream.java:107) at org.apache.poi.poifs.filesystem.ODocumentInputStream.readFully(ODocumentInputStream.java:245) at org.apache.poi.poifs.filesystem.ODocumentInputStream.read(ODocumentInputStream.java:140) at org.apache.poi.poifs.filesystem.DocumentInputStream.read(DocumentInputStream.java:118) at org.apache.poi.poifs.filesystem.DocumentInputStream.read(DocumentInputStream.java:114) at javax.crypto.CipherInputStream.getMoreData(CipherInputStream.java:103) at javax.crypto.CipherInputStream.read(CipherInputStream.java:224) at org.apache.poi.util.BoundedInputStream.read(BoundedInputStream.java:121) at org.apache.poi.util.BoundedInputStream.read(BoundedInputStream.java:103) at org.apache.poi.util.IOUtils.toByteArray(IOUtils.java:48) at test.PoiTest.decrypt(PoiTest.java:22)
> I will add a zip file containing a test case and the xlsx file. the xlsx and its password is enough. I'll have a look onto it.
Created attachment 32103 [details] xlsx file that causes issue (password=pwd123)
Thanks Andreas. Attached xlsx file, password=pwd123.
Can you try it with NPOIFSFileSystem rather than POIFSFileSystem?
With NPOIFSFileSystem, I get: java.lang.IndexOutOfBoundsException: Can't read past the end of the stream at org.apache.poi.poifs.filesystem.NPOIFSStream$StreamBlockByteBufferIterator.next(NPOIFSStream.java:164) at org.apache.poi.poifs.filesystem.NPOIFSStream$StreamBlockByteBufferIterator.next(NPOIFSStream.java:142) at org.apache.poi.poifs.filesystem.NDocumentInputStream.readFully(NDocumentInputStream.java:248) at org.apache.poi.poifs.filesystem.NDocumentInputStream.read(NDocumentInputStream.java:150) at org.apache.poi.poifs.filesystem.DocumentInputStream.read(DocumentInputStream.java:118) at org.apache.poi.poifs.filesystem.DocumentInputStream.read(DocumentInputStream.java:114) at javax.crypto.CipherInputStream.getMoreData(CipherInputStream.java:103) at javax.crypto.CipherInputStream.read(CipherInputStream.java:224) at org.apache.poi.util.BoundedInputStream.read(BoundedInputStream.java:121) at org.apache.poi.util.BoundedInputStream.read(BoundedInputStream.java:103) at org.apache.poi.util.IOUtils.toByteArray(IOUtils.java:48) at test.PoiTest.decrypt(PoiTest.java:22)
Fixed with r1631600 The ole entry size was to big, so I've limited it based on the encrypted size rounded to the next block size.
Thanks for the quick response. I have verified that the latest source fixes this for both POIFSFileSystem and NPOIFSFileSystem.