Skip to content

Commit

Permalink
Use revert() instead of close() when processing fails
Browse files Browse the repository at this point in the history
Otherwise we might write partial changes to the
underlying file which is unexpected.

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1914706 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
centic9 committed Dec 16, 2023
1 parent 4b84986 commit ffc4795
Showing 1 changed file with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -746,24 +746,24 @@ private static PackagePart getPartFromOPCPackage(OPCPackage pkg, String coreDocu
if (coreRel != null) {
PackagePart pp = pkg.getPart(coreRel);
if (pp == null) {
IOUtils.closeQuietly(pkg);
pkg.revert();
throw new POIXMLException("OOXML file structure broken/invalid - core document '" + coreRel.getTargetURI() + "' not found.");
}
return pp;
}

coreRel = pkg.getRelationshipsByType(PackageRelationshipTypes.STRICT_CORE_DOCUMENT).getRelationship(0);
if (coreRel != null) {
IOUtils.closeQuietly(pkg);
pkg.revert();
throw new POIXMLException("Strict OOXML isn't currently supported, please see bug #57699");
}

IOUtils.closeQuietly(pkg);
pkg.revert();
throw new POIXMLException("OOXML file structure broken/invalid - no core document found!");
} catch (POIXMLException e) {
throw e;
} catch (RuntimeException e) {
IOUtils.closeQuietly(pkg);
pkg.revert();
throw new POIXMLException("OOXML file structure broken/invalid", e);
}
}
Expand Down

0 comments on commit ffc4795

Please sign in to comment.