pjfanning opened a new pull request, #1491:
URL: https://github.com/apache/poi/pull/1491

   Follow-up to #1486.
   
   **Problem.** `PackagePart.getOutputStream()` on a `ZipPackagePart` removes 
it from the package and creates a `MemoryPackagePart` in its place. 
`POIXMLDocumentPart`s still hold the old zip part, so reads through it return 
the original zip entry. On a slideshow loaded from a file:
   
   ```java
   pic.setData(newBytes);
   pic.getData();                  // still the old bytes
   ppt.findPictureData(newBytes);  // null
   ```
   
   Separately, `XSLFPictureData` caches its CRC32 and only `setData` refreshes 
it, so writing through `getPackagePart().getOutputStream()` left a stale 
checksum and `findPictureData` missed real duplicates.
   
   **Changes**
   - `ZipPackagePart`: once replaced, forwards `getInputStream`, 
`getOutputStream`, `getSize`, `clear` and `getModificationCount` to the 
replacement part.
   - `PackagePart.getModificationCount()` (new, `@since 6.0.1`): incremented 
each time an output stream is obtained, so callers caching derived data can 
detect writes.
   - `XSLFPictureData`: drops the cached checksum and dimensions when the 
part's modification count changes. `setData` now calls `clear()` first, because 
`MemoryPackagePart` streams append to existing content (a second `setData`, or 
`setData` on a new deck, used to concatenate).
   
   **Tests**
   - `TestPackage.writeToZipPartThroughOldReference`
   - `TestXSLFSlideShow.changePictureDataOfLoadedSlideShow`
   
   `XWPFPictureData` also caches a checksum and can use the same counter. I've 
left it for a separate change.
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)


-- 
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