naruto-lgtm opened a new pull request, #1571:
URL: https://github.com/apache/poi/pull/1571

   Repro: open pie-chart.pptx, remove the chart's graphic frame with 
`slide.removeShape(frame)` and write it. `ppt/charts/chart1.xml` (with the 
plotted values in its `numCache`) and 
`ppt/embeddings/Microsoft_Excel_Worksheet1.xlsx` are still in the file. 
Removing the OLE frame on slide 1 of 45545_Comment.pptx keeps `oleObject1.bin`, 
and removing the SmartArt frame of smartart-simple.pptx keeps the diagram data, 
drawing and its image.
   Cause: `XSLFSheet.removeShape` and `XSLFGroupShape.removeShape` only remove 
the `p:graphicFrame` element. The sheet's relationships to the chart, oleObject 
and diagram parts stay, so the chart data, the embedded workbook or document 
and the SmartArt text are written out although nothing in the deck shows them 
any more (CWE-212). Pictures already get this through `removePictureRelation`.
   Fix: collect the relationship ids the frame refers to before removing it, 
and release each one that nothing left on the sheet refers to. Since #1543, 
`removeRelation` then also removes the parts that only the released part used, 
such as a chart's embedded workbook.
   
   The diagram drawing part is referred to by the diagram data 
(`dsp:dataModelExt/@relId`), not by the frame, so it is added explicitly. An id 
that another shape on the sheet still refers to is kept; the second test 
duplicates a chart frame and checks the chart survives removing one copy and 
goes with the second. `XMLSlideShow.getCharts` now drops charts whose part was 
removed, the same way `getPictureData` handles pictures.
   
   Removing every graphic frame of the pptx samples in test-data (110 frames in 
41 decks) leaves 164 fewer parts in the written files than trunk, with no 
relationship pointing at a missing part (the same three fuzzer/invalid samples 
fail to round-trip on trunk and with the change). External relationships, such 
as a hyperlink URL in a removed table, are left as they were.
   
   `TestXSLFGraphicFrame.testRemoveGraphicFrameRemovesParts` and 
`testRemoveGraphicFrameKeepsSharedParts` fail before the change. The 
`org.apache.poi.xslf` and `org.apache.poi.sl` tests in `:poi-ooxml` (299 tests) 
and `forbiddenApisMain`/`forbiddenApisTest` pass locally on JDK 21.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to