This is an automated email from the ASF dual-hosted git repository.
pjfanning pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/poi.git
The following commit(s) were added to refs/heads/trunk by this push:
new ae71694131 Close the filesystem if HSLF dual-storage lookup fails
(#1251)
ae71694131 is described below
commit ae71694131085a8a0d26c17e428b606a9d210eeb
Author: PJ Fanning <[email protected]>
AuthorDate: Mon Sep 7 13:27:33 2026 +0100
Close the filesystem if HSLF dual-storage lookup fails (#1251)
HSLFSlideShowImpl(DirectoryNode, char[]) already closes the underlying
filesystem when parsing fails, so that HSLFSlideShowImpl(String) does not
leak the file handle it opened. That cleanup does not cover
handleDualStorage, which runs in the super(...) argument and so completes
before the constructor body - and its try block - is entered.
handleDualStorage casts the PP97_DUALSTORAGE entry to DirectoryNode. A
malformed file where that entry is a document rather than a directory
fails the cast with a ClassCastException that escapes past the
constructor's catch, leaking the file handle.
Close the filesystem in handleDualStorage itself and rethrow the original
exception. The cast is left as-is so the exception type callers see for a
malformed file does not change.
Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
---
.../java/org/apache/poi/hslf/usermodel/HSLFSlideShowImpl.java | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)
diff --git
a/poi-scratchpad/src/main/java/org/apache/poi/hslf/usermodel/HSLFSlideShowImpl.java
b/poi-scratchpad/src/main/java/org/apache/poi/hslf/usermodel/HSLFSlideShowImpl.java
index 72e9505ffd..a05dd627b1 100644
---
a/poi-scratchpad/src/main/java/org/apache/poi/hslf/usermodel/HSLFSlideShowImpl.java
+++
b/poi-scratchpad/src/main/java/org/apache/poi/hslf/usermodel/HSLFSlideShowImpl.java
@@ -273,7 +273,16 @@ public final class HSLFSlideShowImpl extends POIDocument
implements Closeable {
if (!dir.hasEntryCaseInsensitive(PP97_DOCUMENT)) {
return dir;
}
- return (DirectoryNode) dir.getEntryCaseInsensitive(PP97_DOCUMENT);
+ try {
+ return (DirectoryNode) dir.getEntryCaseInsensitive(PP97_DOCUMENT);
+ } catch (IOException | RuntimeException e) {
+ // this runs in the super(...) argument of the constructor below,
so the
+ // constructor's own catch block cannot clean up after it. A
malformed file whose
+ // PP97_DUALSTORAGE entry is a document rather than a directory
fails the cast
+ // here, and without this the file handle would leak.
+ IOUtils.closeQuietly(dir.getFileSystem());
+ throw e;
+ }
}
/**
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]