Bug 47958

Summary: ArrayIndexOutOfBoundsException from PicturesTable.getAllPictures() during Escher tree walk
Product: POI Reporter: Trejkaz (pen name) <trejkaz>
Component: HWPFAssignee: POI Developers List <dev>
Status: RESOLVED FIXED    
Severity: normal CC: ehetzner
Priority: P2    
Version: 3.5-FINAL   
Target Milestone: ---   
Hardware: PC   
OS: Windows NT   
Attachments: Sample file

Description Trejkaz (pen name) 2009-10-07 20:27:42 UTC
Created attachment 24360 [details]
Sample file

Put the sample file somewhere, adjust this test to point to the correct file
location and run.

    @Test
    public void testPictureExtractionProblem() throws Exception
    {
        File file = new File("C:\\Data\\Test\\NUIQ021202.doc");
        POIFSFileSystem poifs;
        InputStream stream = new FileInputStream(file);
        try
        {
            poifs = new POIFSFileSystem(stream);
        }
        finally
        {
            stream.close();
        }

        HWPFDocument doc = new HWPFDocument(poifs);

        // Throws ArrayIndexOutOfBoundsException
        doc.getPicturesTable().getAllPictures();
    }

Gives the following error:

java.lang.ArrayIndexOutOfBoundsException: 50206
    at org.apache.poi.util.LittleEndian.getShort(LittleEndian.java:45)
    at
org.apache.poi.ddf.EscherRecord$EscherRecordHeader.readHeader(EscherRecord.java:250)
    at
org.apache.poi.ddf.DefaultEscherRecordFactory.createRecord(DefaultEscherRecordFactory.java:56)
    at
org.apache.poi.hwpf.model.PicturesTable.searchForPictures(PicturesTable.java:171)
    at
org.apache.poi.hwpf.model.PicturesTable.searchForPictures(PicturesTable.java:178)
    at
org.apache.poi.hwpf.model.PicturesTable.searchForPictures(PicturesTable.java:178)
    at
org.apache.poi.hwpf.model.PicturesTable.getAllPictures(PicturesTable.java:202)

There does appear to be a picture in the document but it's unknown to me
whether it's embedded directly or via an OLE2 container (what is known is that
there *is* one OLE2 container in the file.)
Comment 1 Yegor Kozlov 2011-06-24 08:25:01 UTC
Still have the problem in trunk.

Yegor
Comment 2 Sergey Vladimirov 2011-10-30 00:31:42 UTC
*** Bug 50936 has been marked as a duplicate of this bug. ***
Comment 3 Sergey Vladimirov 2011-10-30 00:35:11 UTC
I added workaround to skip pictures that can't be loaded and print an exception for those in logs. It turns out in example files we have more records than pictures present.

Done in revision 1195080