Skip to content

Commit

Permalink
odfdom: check for duplicate Zip entries
Browse files Browse the repository at this point in the history
Add new OdfPackageConstraint PACKAGE_ENTRY_DUPLICATE to report this.

Also fix entriesToMap() which would add the first entry twice.
  • Loading branch information
mistmist committed Jul 3, 2024
1 parent 81526f0 commit af01168
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public enum OdfPackageConstraint implements ValidationConstraint {
/** In case a ZIP entry is using neither STORED and DEFLATED as compression method. */
PACKAGE_ENTRY_USING_INVALID_COMPRESSION(
"The compression method of the ZIP entry '%2$s' is not allowed within the%1$s ODF package file!"),
PACKAGE_ENTRY_DUPLICATE("Duplicate ZIP entry '%2$s'!"),
/** The ODF package shall contain the \"/META-INF/manifest.xml\" file. */
MANIFEST_NOT_IN_PACKAGE(
"The ODF package%1$s shall contain the '" + OdfFile.MANIFEST.getPath() + "' file!"),
Expand Down
10 changes: 9 additions & 1 deletion odfdom/src/main/java/org/odftoolkit/odfdom/pkg/ZipHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ String entriesToMap(Map<String, ZipArchiveEntry> zipEntries) throws IOException,
}
if (zipEntry != null) {
firstEntryName = zipEntry.getName();
addZipEntry(zipEntry, zipEntries);
while (zipEntry != null) {
addZipEntry(zipEntry, zipEntries);
try {
Expand Down Expand Up @@ -130,6 +129,15 @@ private void addZipEntry(ZipArchiveEntry zipEntry, Map<String, ZipArchiveEntry>
mPackage.getBaseURI(),
filePath));
}
if (zipEntries.containsKey(filePath)) {
mPackage
.getErrorHandler()
.fatalError(
new OdfValidationException(
OdfPackageConstraint.PACKAGE_ENTRY_DUPLICATE,
mPackage.getBaseURI(),
filePath));
}
} catch (SAXException ex) {
Logger.getLogger(OdfPackage.class.getName()).log(Level.SEVERE, null, ex);
}
Expand Down

0 comments on commit af01168

Please sign in to comment.