Bug 51187

Summary: Opening and saving PPTX with specific image corrupts file (Power point will no longer open)
Product: POI Reporter: Trey Hyde <thyde>
Component: XSLFAssignee: POI Developers List <dev>
Status: RESOLVED FIXED    
Severity: normal    
Priority: P2    
Version: 3.8-dev   
Target Milestone: ---   
Hardware: PC   
OS: All   
Attachments: File that will be corrupted if you open and save it.
End result of open/close

Description Trey Hyde 2011-05-11 23:09:27 UTC
Created attachment 26986 [details]
File that will be corrupted if you open and save it.

Executing this code against the attached file will create a file that is unreadable PPT.  The PPT contains only a single small image.

  OPCPackage docPackage = OPCPackage.openOrCreate(input);

File output = File.createTempFile("office-ooxml-",null);
            System.out.println(output.getCanonicalPath());
            docPackage.save(output);


Same was true for 3.7 vs 3.8-beta2

In ppt/slides/_rels/slide1.xml.rels I notedd that the target on rId3 went from slide1.xml on the good version to "" on the bad.   Could be more material differences, I just didn't notice.
Comment 1 Trey Hyde 2011-05-11 23:10:23 UTC
Created attachment 26987 [details]
End result of open/close
Comment 2 Trey Hyde 2011-05-11 23:11:54 UTC
Same code scenario as ticket #50154 btw
Comment 3 Nick Burch 2011-05-27 14:36:16 UTC
This looks to be an issue with self references during the save step

I've added a unit test in r1128324 which shows the problem. Someone'll need to dig into the OPC code to try to spot what's going wrong
Comment 4 Yegor Kozlov 2011-08-11 08:13:40 UTC
Fixed in r1156529

Nick is right, it was an issue with saving self references. PackagingURIHelper#relativizeURI resolved self references to an empty string which is wrong. The correct behavior is to return the last segment in the URI. In your case both the source and target URIs are /ppt/slides/slide1.xml and the value written in the relationship part should be slide1.xml (was empty string). 

It appears that self-referencing is legal from the OPC point of view. One way to reproduce the problem in MS Office is to create a .pptx presentation, add a slide and put a hyperlink that points to this slide. The slide will reference itself in /slides/_rels/slide1.xml.rels.  

Yegor