You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@poi.apache.org by ni...@apache.org on 2006/12/14 12:49:57 UTC
svn commit: r487181 - in /jakarta/poi/trunk/src/scratchpad:
src/org/apache/poi/hslf/HSLFSlideShow.java
testcases/org/apache/poi/hslf/data/PictureTypeZero.ppt
testcases/org/apache/poi/hslf/usermodel/TestPictures.java
Author: nick
Date: Thu Dec 14 03:49:56 2006
New Revision: 487181
URL: http://svn.apache.org/viewvc?view=rev&rev=487181
Log:
If we have a picture of type 0, don't even bother trying to create a PictureData object for it
Added:
jakarta/poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/data/PictureTypeZero.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=487181&r1=487180&r2=487181
==============================================================================
--- 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 Thu Dec 14 03:49:56 2006
@@ -255,30 +255,36 @@
List p = new ArrayList();
int pos = 0;
- while (pos < pictstream.length) {
+ // An empty picture record (length 0) will take up 8 bytes
+ while (pos <= (pictstream.length-8)) {
int offset = pos;
- //image signature
+ // Image signature
int signature = LittleEndian.getUShort(pictstream, pos);
pos += LittleEndian.SHORT_SIZE;
- //image type + 0xF018
+ // Image type + 0xF018
int type = LittleEndian.getUShort(pictstream, pos);
pos += LittleEndian.SHORT_SIZE;
- //image size
+ // 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);
- try {
- PictureData pict = PictureData.create(type - 0xF018);
- pict.setRawData(imgdata);
- pict.setOffset(offset);
- p.add(pict);
- } catch(IllegalArgumentException e) {
- System.err.println("Problem reading picture: " + e + "\nYou document will probably become corrupted if you save it!");
- }
+ // 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!");
+ } else {
+ // Build the PictureData object from the data
+ try {
+ PictureData pict = PictureData.create(type - 0xF018);
+ pict.setRawData(imgdata);
+ pict.setOffset(offset);
+ p.add(pict);
+ } catch(IllegalArgumentException e) {
+ System.err.println("Problem reading picture: " + e + "\nYou document will probably become corrupted if you save it!");
+ }
+ }
pos += imgsize;
}
Added: jakarta/poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/data/PictureTypeZero.ppt
URL: http://svn.apache.org/viewvc/jakarta/poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/data/PictureTypeZero.ppt?view=auto&rev=487181
==============================================================================
Binary file - no diff available.
Propchange: jakarta/poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/data/PictureTypeZero.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=487181&r1=487180&r2=487181
==============================================================================
--- 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 Thu Dec 14 03:49:56 2006
@@ -373,5 +373,22 @@
}
+ /**
+ * Test that on a party corrupt powerpoint document, which has
+ * crazy pictures of type 0, we do our best.
+ */
+ public void testZeroPictureType() throws Exception {
+ HSLFSlideShow hslf = new HSLFSlideShow(new File(cwd, "PictureTypeZero.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());
+
+ // TODO: DISABLED: Pending bug #41176
+
+ // Now test what happens when we use the SlideShow interface
+ //SlideShow ppt = new SlideShow(hslf);
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: poi-dev-unsubscribe@jakarta.apache.org
Mailing List: http://jakarta.apache.org/site/mail2.html#poi
The Apache Jakarta POI Project: http://jakarta.apache.org/poi/