pjfanning opened a new issue, #1554: URL: https://github.com/apache/poi/issues/1554
#1543 made `removeSheetAt` and `removeSlide` delete the parts that only the removed sheet or slide used, and #1553 fixes the deck's picture list after `removeShape`. These related gaps are still open. Each could be its own PR. ### 1. Shared strings of a removed sheet stay in `sharedStrings.xml` After `XSSFWorkbook.removeSheetAt`, the removed sheet's text is still in `xl/sharedStrings.xml`, so the written file contains it. This is the same data-remnant problem as #1543 (CWE-212). The table is append-only. Compacting it means renumbering the string indexes of cells in every remaining sheet, including rows SXSSF has already streamed, so it needs its own change. One option is an explicit method that compacts shared strings, called before writing, rather than doing it on every removal. ### 2. Pivot cache data stays after removing the sheet with the pivot table Not yet tested, this is from reading the code. `XSSFSheet.createPivotTable` gives the workbook its own relationship to the `pivotCacheDefinition` part and adds a `pivotCache` entry to `workbook.xml` (`XSSFWorkbook.addPivotCache`). Removing the sheet leaves both in place, so `isRelationshipTarget()` keeps the cache definition. It also keeps the `pivotCacheRecords` part, which holds a full copy of the pivot's source data. If no remaining pivot table uses the cache, the `pivotCache` entry and the workbook relationship should go too, and the cache parts with them. Loaded files are probably affected the same way. ### 3. Index incoming relationships during part removal `POIXMLDocumentPart.isRelationshipTarget()` scans the relationships of every part in the package, once for each child part that might be removed. The #1543 description gives about 160 ms to remove a sheet with 100 pictures at the default 1000-entry limit, and about 2 s with 10,000 pictures. Building an index of incoming relationships once per top-level removal would make this linear. This was agreed as a follow-up in the #1543 review, and is only worth doing if the large case matters. ### 4. XWPF: `removeBodyElement` leaves images, charts and embedded objects behind `XWPFDocument.removeBodyElement` removes the paragraph or table from the body but none of the relations its runs use. So images, charts and embedded objects that only it referenced stay in the package and in the written file. A fix would need to collect the relationship ids the removed element references (blips, charts, OLE objects, hyperlinks), check that nothing else in the document still uses them, and then remove those relations. Headers, footers, footnotes and comments can also reference parts, so the "still used" check has to cover them too. -- 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]
