Bug 46627 - offset of new pictures is sometimes wrong
Summary: offset of new pictures is sometimes wrong
Alias: None
Product: POI
Classification: Unclassified
Component: HSLF (show other bugs)
Version: 3.2-FINAL
Hardware: PC Linux
: P2 normal (vote)
Target Milestone: ---
Assignee: POI Developers List
Depends on:
Reported: 2009-01-29 08:52 UTC by David
Modified: 2009-02-10 11:55 UTC (History)
0 users

patch that fixes the problem for me. (1.91 KB, patch)
2009-01-29 08:53 UTC, David
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description David 2009-01-29 08:52:31 UTC

after images have been removed from a powerpoint file, they are sometimes not really deleted. This causes the calculation of the offset in SlideShow.addPicture to fail. Attached is a patch that bases the calculation on the actual data contained in the file.

HTH, David.
Comment 1 David 2009-01-29 08:53:23 UTC
Created attachment 23193 [details]
patch that fixes the problem for me.
Comment 2 Yegor Kozlov 2009-01-30 06:01:55 UTC
Can you attach a problem ppt file with removed images? The suggested fix looks good but I don't want to commit it without a unit test.

Comment 3 David 2009-02-01 08:30:41 UTC
Sorry, I am having trouble reproducing this problem on a new ppt file. The one that causes problems for me I cannot submit because of company policy, but this happened before on several files, so this does not seem to be an isolated incident. I will try again to reproduce the problem when I have more time (in about a week or so).

bye, David.
Comment 4 Yegor Kozlov 2009-02-01 08:49:05 UTC
I suspect it can be reproduced with PictureTypeZero.ppt or PictureLengthZero.ppt from our collection of test files:


Can check it and post sample code that causes the problem? 

These two files contain invalid images, the first one contains images with unknown type=0, the second one contains images with zero length, i.e. only header and no data.

Comment 5 David 2009-02-09 04:58:50 UTC
You are correct, PictureLengthZero.ppt exposes the problem. Simply adding any picture, like the following code does, should result in an invalid image in the resulting ppt:

   SlideShow ppt = new SlideShow( new ByteArrayInputStream( readFile( args[ 0 ] ) ) );

   int index = ppt.addPicture( readFile( args[ 1 ] ), Picture.PNG );
   Picture picture = new Picture( index );
   ppt.getSlides()[0].addShape( picture );

   ByteArrayOutputStream result = new ByteArrayOutputStream();
   ppt.write( result );

   FileOutputStream os = new FileOutputStream( "output.ppt" );
   os.write( result.toByteArray() );

readFile is a simple function that returns the bytes contained in a file. After applying the patch this works for me.

bye, David.
Comment 6 Yegor Kozlov 2009-02-10 11:55:36 UTC
Fixed in r743080