]> source.dussan.org Git - poi.git/commitdiff
Fix for bug #41357, by moving byte array creation until after we've decided that...
authorNick Burch <nick@apache.org>
Mon, 15 Jan 2007 16:40:03 +0000 (16:40 +0000)
committerNick Burch <nick@apache.org>
Mon, 15 Jan 2007 16:40:03 +0000 (16:40 +0000)
git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/trunk@496398 13f79535-47bb-0310-9956-ffa450edef68

src/scratchpad/src/org/apache/poi/hslf/HSLFSlideShow.java
src/scratchpad/testcases/org/apache/poi/hslf/data/PictureLengthZero.ppt [new file with mode: 0644]
src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestPictures.java

index 774129a9ccdc48ffaab39fbeb9f41085a6aceae9..513d42ab50716a02ba50f05684f85e77be99d88b 100644 (file)
@@ -270,8 +270,6 @@ public class HSLFSlideShow extends POIDocument
             // Image size (excluding the 8 byte header)
             int imgsize = LittleEndian.getInt(pictstream, pos);
             pos += LittleEndian.INT_SIZE;
-            byte[] imgdata = new byte[imgsize];
-            System.arraycopy(pictstream, pos, imgdata, 0, imgdata.length);
 
                        // The image size must be 0 or greater
                        // (0 is allowed, but odd, since we do wind on by the header each
@@ -282,8 +280,15 @@ public class HSLFSlideShow extends POIDocument
 
                        // If they type (including the bonus 0xF018) is 0, skip it
                        if(type == 0) {
-                               System.err.println("Problem reading picture: Invalid image type 0, on picture with length" + imgsize + ".\nYou document will probably become corrupted if you save it!");
+                               System.err.println("Problem reading picture: Invalid image type 0, on picture with length " + imgsize + ".\nYou document will probably become corrupted if you save it!");
+                               System.err.println(pos);
                        } else {
+                   // Copy the data, ready to pass to PictureData
+                   byte[] imgdata = new byte[imgsize];
+                   if(imgsize > 0) {
+                       System.arraycopy(pictstream, pos, imgdata, 0, imgdata.length);
+                   }
+                   
                                // Build the PictureData object from the data
                                try {
                                        PictureData pict = PictureData.create(type - 0xF018);
diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/data/PictureLengthZero.ppt b/src/scratchpad/testcases/org/apache/poi/hslf/data/PictureLengthZero.ppt
new file mode 100644 (file)
index 0000000..1cb0cda
Binary files /dev/null and b/src/scratchpad/testcases/org/apache/poi/hslf/data/PictureLengthZero.ppt differ
index f78e9df8248dc1204b3107470cfc610c6b611315..797f97cda729227636f96f6f546bae8aad8df4e3 100644 (file)
@@ -387,9 +387,54 @@ public class TestPictures extends TestCase{
                assertEquals(Picture.WMF, hslf.getPictures()[0].getType());
                assertEquals(Picture.WMF, hslf.getPictures()[1].getType());
 
-               // TODO: DISABLED: Pending bug #41176
+               // Now test what happens when we use the SlideShow interface
+               SlideShow ppt = new SlideShow(hslf);
+        Slide[] slides = ppt.getSlides();
+        PictureData[] pictures = ppt.getPictureData();
+        assertEquals(12, slides.length);
+        assertEquals(2, pictures.length);
+        
+               Picture pict;
+               PictureData pdata;
+               
+        pict = (Picture)slides[0].getShapes()[1]; // 2nd object on 1st slide
+        pdata = pict.getPictureData();
+        assertTrue(pdata instanceof WMF);
+        assertEquals(Picture.WMF, pdata.getType());
+               
+        pict = (Picture)slides[0].getShapes()[2]; // 3rd object on 1st slide
+        pdata = pict.getPictureData();
+        assertTrue(pdata instanceof WMF);
+        assertEquals(Picture.WMF, pdata.getType());
+       }
+       
+       public void testZeroPictureLength() throws Exception {
+               HSLFSlideShow hslf = new HSLFSlideShow(new File(cwd, "PictureLengthZero.ppt").getPath());
 
+               // Should still have 2 real pictures
+               assertEquals(2, hslf.getPictures().length);
+               // Both are real pictures, both WMF
+               assertEquals(Picture.WMF, hslf.getPictures()[0].getType());
+               assertEquals(Picture.WMF, hslf.getPictures()[1].getType());
+               
                // Now test what happens when we use the SlideShow interface
-               //SlideShow ppt = new SlideShow(hslf);
+               SlideShow ppt = new SlideShow(hslf);
+        Slide[] slides = ppt.getSlides();
+        PictureData[] pictures = ppt.getPictureData();
+        assertEquals(27, slides.length);
+        assertEquals(2, pictures.length);
+        
+               Picture pict;
+               PictureData pdata;
+               
+        pict = (Picture)slides[6].getShapes()[13];
+        pdata = pict.getPictureData();
+        assertTrue(pdata instanceof WMF);
+        assertEquals(Picture.WMF, pdata.getType());
+               
+        pict = (Picture)slides[7].getShapes()[13];
+        pdata = pict.getPictureData();
+        assertTrue(pdata instanceof WMF);
+        assertEquals(Picture.WMF, pdata.getType());
        }
 }