Skip to content

Upgrade zip4j to 2.11.6 and report archive write failures - #580

Open
tonygermano wants to merge 1 commit into
test/extension-controller-tempdirfrom
build/zip4j-2.11.6
Open

tonygermano wants to merge 1 commit into
test/extension-controller-tempdirfrom
build/zip4j-2.11.6

Conversation

@tonygermano

@tonygermano tonygermano commented Nov 16, 2026 •

Copy link
Copy Markdown
Member

Upgrades zip4j from the vendored 1.3.3 jar to net.lingala.zip4j:zip4j:2.11.6 from Maven Central, and makes archive failures visible.

  • zip4j is only used to write password-protected ZIP exports and data-pruner archives. ArchiveUtils is ported to the 2.x API, and EncryptionType.getKeyStrength() now returns an AesKeyStrength.
  • Deletes our patched Unzip and UnzipEngine and their tests. Nothing in the engine extracts with zip4j, and they depend on 1.x internals.
  • A failure finishing an archive (disk full, for example) used to be swallowed for TAR and for ZIP with a compressor, and a truncated archive was moved into place. It is now reported, the file is closed, and the half-written archive is removed. If archiving succeeds and only moving the finished archive into place fails, that archive is kept.
  • A password combined with TAR or a compressor used to be silently ignored, writing an unprotected archive. It is now rejected before anything is written.
  • The headers of the touched main and test files are converted to SPDX.

Behavior change: a data pruner configured with a password plus TAR or a compressor, which the administrator UI can't produce but the API or a hand-edited configuration can, now fails on each run instead of archiving unprotected. Its channel isn't pruned until the configuration is fixed.

Relates to #337 and #472, without resolving either.

Claude checked:

  • ./gradlew clean build dist passes on this branch.
  • The new tests fail against the old code where they should: encrypted ZIP round-trips for each encryption type (including the JDK refusing the archive), TAR, tar.gz, zip.gz and empty-folder output, write failures to /dev/full for each format, and the password rules.
  • The smoke test passes 7 of 7 against a server built from this branch, and the server-side archive's entries are AES-encrypted. The same test passes 6 of 6 on the previous zip4j 1.3.3.

Reviewer notes

  • Separate existing bug, fixed in its own PR rather than here: the query-parameter variant of the server export endpoint (MessageServlet, getMessageWriterOptions) never sets passwordEnabled, so a password sent that way is dropped and an unprotected ZIP is written.
  • ArchiveUtils.java gets a little smaller if you hide whitespace changes

Release notes

  • Upgraded zip4j from 1.3.3 to 2.11.6.
  • Message export and the data pruner now report a failure to finish an archive instead of leaving a truncated archive in place.
  • A password is now rejected for any archive format except a plain ZIP, instead of being ignored. A data pruner configured with a password and TAR or a compressor now fails until it is corrected.

🤖 Drafted with Claude Code

Replace the vendored zip4j 1.3.3 jars in server/lib and client/lib with the
net.lingala.zip4j:zip4j:2.11.6 Maven Central artifact, which has no
dependencies of its own. It still stages into server-lib and client-lib, now
as zip4j-2.11.6.jar.

Zip4j is only used to write password-protected ZIP archives, which the JRE and
commons-compress cannot do. Port ArchiveUtils to the 2.x API; the password is
now given to the ZipOutputStream. EncryptionType no longer exposes zip4j 1.x
integer constants and returns an AesKeyStrength instead. Entry names are
written with forward slashes, as zip requires, whatever the platform.

Delete our modified copies of Unzip and UnzipEngine, which carried a Zip Slip
fix for zip4j 1.x extraction. Nothing in the engine extracts with zip4j (the
extension installer uses java.util.zip and has its own check), and the copies
are built against 1.x internals that no longer exist. Remove them from the
client-core jar, drop their tests, the THIRD-PARTY-README note and the
ZipTestUtils method only they used.

Make failures writing an archive visible and leave nothing behind:

- ArchiveUtils now closes the archive explicitly, for every format, so a
  failure writing its end (the zip central directory, the tar end-of-archive
  records, a compressor's footer) is reported. It used to be swallowed by
  closeQuietly for tar and for ZIP with a compressor, so a full disk gave a
  truncated archive that was moved into place and the source folder deleted.
- Zip4j 2.x does not close the underlying stream when finishing the archive
  fails, as 1.x did, so ArchiveUtils keeps the FileOutputStream and closes it
  itself. Entries are closed only after a successful copy: closing them in a
  finally block replaced the original failure, for example a full disk, with a
  NullPointerException from closing an entry that was never opened.
- MessageWriterArchive deletes the file the archive was being built in when
  archiving fails. If only moving the finished archive into place fails, it
  keeps that file.

Only plain ZIP archives can be password protected. Previously a password
combined with another archiver or with a compressor was silently ignored and
an unprotected archive was written. MessageWriterFactory now rejects that
combination when the writer is created, before any message is written, and
ArchiveUtils.createArchive refuses it as well. A data pruner configured this
way, which the administrator cannot produce but the API or a hand-edited
configuration can, now fails on each run instead of archiving unprotected,
so its channel is not pruned until the configuration is corrected. Correct
the stale comment about commons-compress while there.

Tests: encrypted ZIP output for each encryption type (method, key strength,
extraction with the password, rejection of a wrong one, and the JDK refusing
the archive); tar, tar.gz, zip.gz and empty-folder output; writes to
/dev/full for each format, which are skipped where that is unavailable; the
password rules, including that a password is ignored when not enabled; and
MessageWriterArchive end to end, including keeping a finished archive that
could not be moved into place. The smoke test also checks that a password
for a TAR is refused. Only the zip4j checksums are added to the verification
metadata; unrelated missing entries are left for a separate cleanup.

Issue: #337
Issue: #472
Assisted-by: Claude:claude-sonnet-5-5
Signed-off-by: Tony Germano <tony@germano.name>
@tonygermano
tonygermano added this pull request to stack #581 November 16, 2026 16:59
@tonygermano
tonygermano requested a review from a team as a code owner November 16, 2026 16:59
@tonygermano tonygermano added the bug Something isn't working label Nov 16, 2026
@tonygermano
tonygermano requested review from gibson9583 and kayyagari and removed request for a team November 16, 2026 16:59
@tonygermano tonygermano added the dependencies Dependency updates label Nov 16, 2026
@tonygermano tonygermano added the java Java / Gradle dependencies label Nov 16, 2026
@tonygermano tonygermano added the licensing Eclipse Intellectual Property (IP) due diligence: licensing, provenance, Dash results, IP reviews label Nov 16, 2026
@github-actions

github-actions Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

Test Results

  143 files  ± 0    143 suites  ±0   4m 25s ⏱️ +16s
  984 tests +11    984 ✅ +11  0 💤 ±0  0 ❌ ±0 
1 308 runs  +17  1 302 ✅ +17  6 💤 ±0  0 ❌ ±0 

Results for commit f337c56. ± Comparison against base commit 7cc7cd5.

This pull request removes 13 and adds 24 tests. Note that renamed tests count towards both.
net.lingala.zip4j.unzip.UnzipEngineTest ‑ testUnzipWithMaliciousFile1
net.lingala.zip4j.unzip.UnzipEngineTest ‑ testUnzipWithMaliciousFileAndMaliciousNewFileName
net.lingala.zip4j.unzip.UnzipEngineTest ‑ testUnzipWithMaliciousFileButValidNewFileName
net.lingala.zip4j.unzip.UnzipEngineTest ‑ testUnzipWithNormalFile1
net.lingala.zip4j.unzip.UnzipEngineTest ‑ testUnzipWithNormalFile2
net.lingala.zip4j.unzip.UnzipEngineTest ‑ testUnzipWithNormalFileButMaliciousNewFileName
net.lingala.zip4j.unzip.UnzipTest ‑ testExtractAllFromMaliciousFile
net.lingala.zip4j.unzip.UnzipTest ‑ testExtractAllFromNormalFile
net.lingala.zip4j.unzip.UnzipTest ‑ testExtractMaliciousFile1
net.lingala.zip4j.unzip.UnzipTest ‑ testExtractMaliciousFile2
…
com.mirth.connect.util.ArchiveUtilsTest ‑ testCreateTar
com.mirth.connect.util.ArchiveUtilsTest ‑ testCreateTarGz
com.mirth.connect.util.ArchiveUtilsTest ‑ testCreateZipAes128
com.mirth.connect.util.ArchiveUtilsTest ‑ testCreateZipAes256
com.mirth.connect.util.ArchiveUtilsTest ‑ testCreateZipFromEmptyFolder
com.mirth.connect.util.ArchiveUtilsTest ‑ testCreateZipGz
com.mirth.connect.util.ArchiveUtilsTest ‑ testCreateZipStandardEncryption
com.mirth.connect.util.ArchiveUtilsTest ‑ testCreateZipUnencrypted
com.mirth.connect.util.ArchiveUtilsTest ‑ testPasswordRejectedForNonZipArchive
com.mirth.connect.util.ArchiveUtilsTest ‑ testPasswordRejectedForZipWithCompressor
…

♻️ This comment has been updated with latest results.

@mgaffigan mgaffigan left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Love it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working dependencies Dependency updates java Java / Gradle dependencies licensing Eclipse Intellectual Property (IP) due diligence: licensing, provenance, Dash results, IP reviews

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants