Skip to content

Commit

Permalink
Merge pull request #443 from win32kbase/master
Browse files Browse the repository at this point in the history
Fix potential file handle leak from zip CRC logic backport
  • Loading branch information
win32kbase authored Jan 4, 2022
2 parents 1f8cc84 + 8b09c07 commit f89a46b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 13 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<groupId>me.coley</groupId>
<artifactId>recaf</artifactId>
<url>https://github.com/Col-E/Recaf/</url>
<version>2.21.9</version>
<version>2.21.10</version>
<name>Recaf</name>
<description>A modern java bytecode editor</description>
<!-- Variables -->
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/me/coley/recaf/Recaf.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
* @author Matt
*/
public class Recaf {
public static final String VERSION = "2.21.9";
public static final String VERSION = "2.21.10";
public static final String DOC_URL = "https://col-e.github.io/Recaf-documentation/";
public static final int ASM_VERSION = Opcodes.ASM9;
private static Controller currentController;
Expand Down
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 f89a46b

Please sign in to comment.