If we have a picture of type 0, don't even bother trying to create a PictureData object for it

git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/trunk@487181 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Nick Burch 2006-12-14 11:49:56 +00:00
parent 732d49a15b
commit 5c5dcf0d4f
3 changed files with 36 additions and 13 deletions

View File

@ -255,22 +255,27 @@ public class HSLFSlideShow extends POIDocument
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);
// 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);
@ -279,6 +284,7 @@ public class HSLFSlideShow extends POIDocument
} catch(IllegalArgumentException e) {
System.err.println("Problem reading picture: " + e + "\nYou document will probably become corrupted if you save it!");
}
}
pos += imgsize;
}

View File

@ -373,5 +373,22 @@ public class TestPictures extends TestCase{
}
/**
* 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);
}
}