Skip to content

Commit

Permalink
fix: Fix file handle leak from 3x zip file logic backport
Browse files Browse the repository at this point in the history
  • Loading branch information
win32kbase committed Jan 4, 2022
1 parent 235e87a commit 1c855ec
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions src/main/java/me/coley/recaf/workspace/JarResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,19 +63,20 @@ protected Map<String, byte[]> loadClasses() throws IOException {
// This may not always be ideal, but this way has one major bonus. It totally ignores CRC validity.
// It also ignores a few other zip entry values.
// Since somebody can intentionally write bogus data there to crash "ZipInputStream" this way works.
ZipFile zf = new ZipFile(getPath().toString());
Enumeration<? extends ZipEntry> entries = zf.entries();
while (entries.hasMoreElements()) {
ZipEntry entry = entries.nextElement();
try (ZipFile zf = new ZipFile(getPath().toString())) {
Enumeration<? extends ZipEntry> entries = zf.entries();
while (entries.hasMoreElements()) {
ZipEntry entry = entries.nextElement();

if (shouldSkip(entry.getName()))
continue;
if (!loader.isValidClassEntry(entry))
continue;
if (shouldSkip(entry.getName()))
continue;
if (!loader.isValidClassEntry(entry))
continue;

InputStream zis = zf.getInputStream(entry);
byte[] in = IOUtil.toByteArray(zis);
loader.onClass(entry.getName(), in);
InputStream zis = zf.getInputStream(entry);
byte[] in = IOUtil.toByteArray(zis);
loader.onClass(entry.getName(), in);
}
}
}
}
Expand Down

0 comments on commit 1c855ec

Please # to comment.