Skip to content

Load legacy ZIP64 JARs leniently#365

Merged
nbauma109 merged 1 commit into
masterfrom
codex/load-legacy-zip64-jars
Jun 30, 2026
Merged

Load legacy ZIP64 JARs leniently#365
nbauma109 merged 1 commit into
masterfrom
codex/load-legacy-zip64-jars

Conversation

@nbauma109

@nbauma109 nbauma109 commented Jun 30, 2026

Copy link
Copy Markdown
Owner

Fixes #363

Copilot AI review requested due to automatic review settings June 30, 2026 08:18
return FileSystems.newFileSystem(uri, Collections.emptyMap());
} catch (ZipException e) {
// Rewrite entries through ZipInputStream to discard malformed CEN metadata.
Path sanitizedArchive = Files.createTempFile("jd-gui-duo-", getExtension(file));

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 194c9a5beb

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

}
}

return FileSystems.newFileSystem(sanitizedArchive, (ClassLoader)null);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Reuse sanitized file systems for repeated opens

When this ZipException fallback is used, the returned zipfs is registered for sanitizedArchive, not for the original uri that load() checks with FileSystems.getFileSystem(uri). Reopening or reloading the same legacy JAR therefore never reuses the existing file system and rewrites another temp archive that is kept open until JVM exit, so repeated opens leak file handles and temp files; cache the fallback by original URI or otherwise make the original lookup hit the sanitized file system.

Useful? React with 👍 / 👎.

@nbauma109
nbauma109 force-pushed the codex/load-legacy-zip64-jars branch from 194c9a5 to 06d5772 Compare June 30, 2026 08:26

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR addresses ZIP/JAR import failures caused by strict ZIP64/CEN parsing in the JDK ZipFS provider by adding a fallback that rewrites malformed archives into a sanitized temporary ZIP/JAR before opening them as a FileSystem. It also adds a regression test and build plumbing to fetch a known legacy/malformed JAR.

Changes:

  • Add a ZipException fallback in ZipFileLoaderProvider that rewrites entries via ZipInputStream/ZipOutputStream and opens the sanitized archive with ZipFS.
  • Add a JUnit test that loads aspectjweaver-1.8.13.jar and asserts expected JAR structure/container detection.
  • Update the services Maven module to download the test JAR during generate-test-resources and add a test-scoped coordinate reference.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

File Description
services/src/main/java/org/jd/gui/service/fileloader/ZipFileLoaderProvider.java Adds ZipFS fallback that sanitizes malformed ZIP/JARs by rewriting entries into a temporary archive.
services/src/test/java/org/jd/gui/service/fileloader/JarFileLoaderProviderTest.java Adds regression coverage for loading a legacy/malformed JAR and verifying expected structure.
services/pom.xml Adds build step to copy the test JAR into target/test-jars and declares a test dependency coordinate.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +4 to +6
* This is a Copyleft license that gives the user the right to use,
* copy and modify the code freely for non-commercial purposes.
*/
Comment on lines +11 to 12
import org.apache.commons.io.FilenameUtils;
import org.jd.core.v1.service.converter.classfiletojavasyntax.util.ExceptionUtil;
Comment on lines +105 to +108
private String getExtension(File file) {
String extension = FilenameUtils.getExtension(file.getName());
return extension.isEmpty() ? ".zip" : '.' + extension;
}
Comment on lines +82 to +89
private FileSystem newFileSystem(URI uri, File file) throws IOException {
try {
return FileSystems.newFileSystem(uri, Collections.emptyMap());
} catch (ZipException e) {
// Rewrite entries through ZipInputStream to discard malformed CEN metadata.
Path sanitizedArchive = Files.createTempFile("jd-gui-duo-", getExtension(file));
sanitizedArchive.toFile().deleteOnExit();

@sonarqubecloud

Copy link
Copy Markdown

@nbauma109
nbauma109 merged commit cf426aa into master Jun 30, 2026
3 of 5 checks passed
@nbauma109
nbauma109 deleted the codex/load-legacy-zip64-jars branch June 30, 2026 08:29

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 06d5772875

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

}
}

return FileSystems.newFileSystem(sanitizedArchive, (ClassLoader)null);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Reject non-ZIP files after an empty fallback rewrite

In the fallback path for a .jar/.zip that is not actually a ZIP, or is corrupt before the first local header, ZipInputStream.getNextEntry() returns null rather than throwing, so the code writes a brand-new empty ZIP and then returns a valid FileSystem for it. That makes load() report success and show an empty archive instead of rejecting the bad input; guard that at least one entry was copied, or rethrow the original ZipException, before opening the sanitized archive.

Useful? React with 👍 / 👎.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Import ZIP Error

3 participants