From: Sergey Vladimirov Date: Sun, 30 Oct 2011 00:33:44 +0000 (+0000) Subject: Fix 47958 - ArrayIndexOutOfBoundsException from PicturesTable.getAllPictures() during... X-Git-Tag: REL_3_8_BETA5~37 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=16ff31e5ad60ef3aa50dbf630dbd7ca5b7ed7d14;p=poi.git Fix 47958 - ArrayIndexOutOfBoundsException from PicturesTable.getAllPictures() during Escher tree walk Fix 50936 - Exception parsing MS Word 8.0 file (as duplicate of 47958) git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1195080 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/documentation/content/xdocs/status.xml b/src/documentation/content/xdocs/status.xml index 0ff1959b25..37acaacf3d 100644 --- a/src/documentation/content/xdocs/status.xml +++ b/src/documentation/content/xdocs/status.xml @@ -34,6 +34,8 @@ + 50936 - Exception parsing MS Word 8.0 file (as duplicate of 47958) + 47958 - ArrayIndexOutOfBoundsException from PicturesTable.getAllPictures() during Escher tree walk 51944 - PAPFormattedDiskPage.getPAPX - IndexOutOfBounds 52032 - HWPF - ArrayIndexOutofBoundsException with no stack trace (broken after revision 1178063) support for converting pptx files into images with a PPTX2PNG tool diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/PicturesTable.java b/src/scratchpad/src/org/apache/poi/hwpf/model/PicturesTable.java index 1d5b28459b..c0b440ff16 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/PicturesTable.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/PicturesTable.java @@ -20,6 +20,10 @@ package org.apache.poi.hwpf.model; import java.util.ArrayList; import java.util.List; +import org.apache.poi.util.POILogFactory; + +import org.apache.poi.util.POILogger; + import org.apache.poi.ddf.DefaultEscherRecordFactory; import org.apache.poi.ddf.EscherBSERecord; import org.apache.poi.ddf.EscherBlipRecord; @@ -52,6 +56,9 @@ import org.apache.poi.util.LittleEndian; @Internal public final class PicturesTable { + private static final POILogger logger = POILogFactory + .getLogger( PicturesTable.class ); + static final int TYPE_IMAGE = 0x08; static final int TYPE_IMAGE_WORD2000 = 0x00; static final int TYPE_IMAGE_PASTED_FROM_CLIPBOARD = 0xA; @@ -175,18 +182,32 @@ public final class PicturesTable { pictures.add(new Picture(blip.getPicturedata())); } - else if (bse.getOffset() > 0) - { - // Blip stored in delay stream, which in a word doc, is the main stream - EscherRecordFactory recordFactory = new DefaultEscherRecordFactory(); - EscherRecord record = recordFactory.createRecord(_mainStream, bse.getOffset()); - - if (record instanceof EscherBlipRecord) { - record.fillFields(_mainStream, bse.getOffset(), recordFactory); - blip = (EscherBlipRecord) record; - pictures.add(new Picture(blip.getPicturedata())); - } - } + else if ( bse.getOffset() > 0 ) + { + try + { + // Blip stored in delay stream, which in a word doc, is + // the main stream + EscherRecordFactory recordFactory = new DefaultEscherRecordFactory(); + EscherRecord record = recordFactory.createRecord( + _mainStream, bse.getOffset() ); + + if ( record instanceof EscherBlipRecord ) + { + record.fillFields( _mainStream, bse.getOffset(), + recordFactory ); + blip = (EscherBlipRecord) record; + pictures.add( new Picture( blip.getPicturedata() ) ); + } + } + catch ( Exception exc ) + { + logger.log( + POILogger.WARN, + "Unable to load picture from BLIB record at offset #", + Integer.valueOf( bse.getOffset() ), exc ); + } + } } // Recursive call. diff --git a/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestBugs.java b/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestBugs.java index 593bd8419d..5aa15eeef7 100644 --- a/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestBugs.java +++ b/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestBugs.java @@ -463,23 +463,12 @@ public class TestBugs extends TestCase } /** - * [FAILING] Bug 47958 - Exception during Escher walk of pictures + * Bug 47958 - Exception during Escher walk of pictures */ public void test47958() { HWPFDocument doc = HWPFTestDataSamples.openSampleFile( "Bug47958.doc" ); - try - { - for ( Picture pic : doc.getPicturesTable().getAllPictures() ) - { - System.out.println( pic.suggestFullFileName() ); - } - fixed( "47958" ); - } - catch ( Exception e ) - { - // expected exception - } + doc.getPicturesTable().getAllPictures(); } /** @@ -513,11 +502,33 @@ public class TestBugs extends TestCase } /** - * Bug 50936 - HWPF fails to read a file + * Bug 50936 - Exception parsing MS Word 8.0 file + */ + public void test50936_1() + { + HWPFDocument hwpfDocument = HWPFTestDataSamples + .openSampleFile( "Bug50936_1.doc" ); + hwpfDocument.getPicturesTable().getAllPictures(); + } + + /** + * Bug 50936 - Exception parsing MS Word 8.0 file + */ + public void test50936_2() + { + HWPFDocument hwpfDocument = HWPFTestDataSamples + .openSampleFile( "Bug50936_2.doc" ); + hwpfDocument.getPicturesTable().getAllPictures(); + } + + /** + * Bug 50936 - Exception parsing MS Word 8.0 file */ - public void test50936() + public void test50936_3() { - HWPFTestDataSamples.openSampleFile( "Bug50936.doc" ); + HWPFDocument hwpfDocument = HWPFTestDataSamples + .openSampleFile( "Bug50936_3.doc" ); + hwpfDocument.getPicturesTable().getAllPictures(); } /** diff --git a/test-data/document/Bug50936.doc b/test-data/document/Bug50936.doc deleted file mode 100644 index 3a700adb74..0000000000 Binary files a/test-data/document/Bug50936.doc and /dev/null differ diff --git a/test-data/document/Bug50936_1.doc b/test-data/document/Bug50936_1.doc new file mode 100644 index 0000000000..3a700adb74 Binary files /dev/null and b/test-data/document/Bug50936_1.doc differ diff --git a/test-data/document/Bug50936_2.doc b/test-data/document/Bug50936_2.doc new file mode 100644 index 0000000000..d153eef3a6 Binary files /dev/null and b/test-data/document/Bug50936_2.doc differ diff --git a/test-data/document/Bug50936_3.doc b/test-data/document/Bug50936_3.doc new file mode 100644 index 0000000000..7a644b7e1e Binary files /dev/null and b/test-data/document/Bug50936_3.doc differ