Bug 60499 - Deleting a picture that is used twice on a slide corrupt the slide
Summary: Deleting a picture that is used twice on a slide corrupt the slide
Status: RESOLVED FIXED
Alias: None
Product: POI
Classification: Unclassified
Component: XSLF (show other bugs)
Version: 3.16-dev
Hardware: PC All
: P2 normal (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-12-20 10:02 UTC by Aurélien
Modified: 2017-09-17 22:54 UTC (History)
1 user (show)



Attachments
A test PPT with an image used twice, and a java code with a main to reproduce the problem (30.42 KB, application/x-zip-compressed)
2016-12-20 10:02 UTC, Aurélien
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Aurélien 2016-12-20 10:02:57 UTC
Created attachment 34536 [details]
A test PPT with an image used twice, and a java code with a main to reproduce the problem

If the same picture is referenced twice in a slide (with 2 XSLFPictureShape), deleting one of the XSLFPictureShape will corrupt the slide. By corrupted, I mean that PowerPoint won't be able to load the slide and it will replace its content with a blank slide.
I am guessing that XSLF always deletes the image file along with the XSLFPictureShape. What should be done is deleting the image file only if it is not used by other XSLFPictureShape elements.

To create a slide with the same picture referenced twice:
1. insert a picture in a slide,
2. copy and past the inserted picture in the current slide.
The same picture should be duplicated in the slide.

I have put attached a zip file with:
- a PPT with one slide and an image used twice in that slide,
- a java class with a small main() to reproduce the probleme.
Comment 1 Andreas Beeker 2017-09-17 22:54:07 UTC
I regard the original issue as invalid - if you have multiple references to the same part (e.g. a png image), you would have each time a new relationship - i.e. relationships aren't reused. I have to admit, that I haven't search the ECMA spec for this definition, but if you do the same manually via MS/Libre Office you actually get not only a copied relationship but also a second media part.

After I adopted your sample to this handling, the resulting pptx was still corrupt as the POIXMLDocumentPart.removeRelation(POIXMLDocumentPart) method didn't handle multiple references correct.

This was fixed via r1808661