Author: nick
Date: Mon Jan 15 08:40:03 2007
New Revision: 496398

URL: http://svn.apache.org/viewvc?view=rev&rev=496398
Log:
Fix for bug #41357, by moving byte array creation until after we've decided 
that we have a valid picture

Added:
    
jakarta/poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/data/PictureLengthZero.ppt
   (with props)
Modified:
    jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/HSLFSlideShow.java
    
jakarta/poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestPictures.java

Modified: 
jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/HSLFSlideShow.java
URL: 
http://svn.apache.org/viewvc/jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/HSLFSlideShow.java?view=diff&rev=496398&r1=496397&r2=496398
==============================================================================
--- jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/HSLFSlideShow.java 
(original)
+++ jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/HSLFSlideShow.java 
Mon Jan 15 08:40:03 2007
@@ -270,8 +270,6 @@
             // 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 @@
 
                        // 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);

Added: 
jakarta/poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/data/PictureLengthZero.ppt
URL: 
http://svn.apache.org/viewvc/jakarta/poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/data/PictureLengthZero.ppt?view=auto&rev=496398
==============================================================================
Binary file - no diff available.

Propchange: 
jakarta/poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/data/PictureLengthZero.ppt
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Modified: 
jakarta/poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestPictures.java
URL: 
http://svn.apache.org/viewvc/jakarta/poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestPictures.java?view=diff&rev=496398&r1=496397&r2=496398
==============================================================================
--- 
jakarta/poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestPictures.java
 (original)
+++ 
jakarta/poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestPictures.java
 Mon Jan 15 08:40:03 2007
@@ -387,9 +387,54 @@
                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());
        }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
Mailing List:    http://jakarta.apache.org/site/mail2.html#poi
The Apache Jakarta POI Project: http://jakarta.apache.org/poi/

Reply via email to