Skip to content

Commit ff244dd

Browse files
committed
fix: Improve detection of red-herring junk data masquarading as classes due to conflicting zip file entries
1 parent b63aa8c commit ff244dd

File tree

3 files changed

+29
-8
lines changed

3 files changed

+29
-8
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<groupId>me.coley</groupId>
44
<artifactId>recaf</artifactId>
55
<url>https://github.com/Col-E/Recaf/</url>
6-
<version>2.19.2</version>
6+
<version>2.19.3</version>
77
<name>Recaf</name>
88
<description>A modern java bytecode editor</description>
99
<!-- Variables -->

src/main/java/me/coley/recaf/Recaf.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
* @author Matt
3232
*/
3333
public class Recaf {
34-
public static final String VERSION = "2.19.2";
34+
public static final String VERSION = "2.19.3";
3535
public static final String DOC_URL = "https://col-e.github.io/Recaf-documentation/";
3636
public static final int ASM_VERSION = Opcodes.ASM9;
3737
private static Controller currentController;

src/main/java/me/coley/recaf/workspace/EntryLoader.java

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package me.coley.recaf.workspace;
22

3+
import me.coley.cafedude.InvalidClassException;
4+
import me.coley.cafedude.io.ClassFileReader;
35
import me.coley.recaf.plugin.PluginsManager;
46
import me.coley.recaf.plugin.api.LoadInterceptorPlugin;
57
import me.coley.recaf.util.ClassUtil;
@@ -24,6 +26,7 @@ public class EntryLoader {
2426
private final Map<String, byte[]> classes = new HashMap<>();
2527
private final Map<String, byte[]> files = new HashMap<>();
2628
private final Map<String, byte[]> invalidClasses = new HashMap<>();
29+
private final Map<String, byte[]> invalidJunkClasses = new HashMap<>();
2730

2831
/**
2932
* @return New archive entry loader instance.
@@ -52,14 +55,32 @@ public static EntryLoader create() {
5255
public boolean onClass(String entryName, byte[] value) {
5356
// Check if class is valid. If it is not it will be stored for later.
5457
if (!ClassUtil.isValidClass(value)) {
55-
if (invalidClasses.containsKey(entryName)) {
56-
debug("Skipping duplicate invalid class '{}'", entryName);
58+
try {
59+
// If the data can be read, overwrite whatever entry we have previously seen
60+
new ClassFileReader().read(value);
61+
invalidClasses.put(entryName, value);
62+
if (invalidJunkClasses.remove(entryName) != null) {
63+
debug("Replacing class '{}' previously associated with non-class junk with" +
64+
" newly discovered class data", entryName);
65+
}
66+
return false;
67+
} catch (InvalidClassException e) {
68+
// Skip if we think this is junk data that is masking an invalid class we already recovered
69+
if (invalidClasses.containsKey(entryName)) {
70+
debug("Skipping masking junk data for class '{}'", entryName);
71+
return false;
72+
}
73+
// Doesnt look like the CAFEDOOD backup parser can read it either.
74+
if (invalidJunkClasses.containsKey(entryName)) {
75+
// Already seen it. Probably dupe junk data.
76+
debug("Skipping duplicate invalid class '{}'", entryName);
77+
return false;
78+
} else {
79+
debug("Invalid class detected, not parsable by backup reader \"{}\"", entryName);
80+
}
81+
invalidJunkClasses.put(entryName, value);
5782
return false;
58-
} else {
59-
debug("Invalid class detected \"{}\"", entryName);
6083
}
61-
invalidClasses.put(entryName, value);
62-
return false;
6384
}
6485
// Check if we've already seen this class
6586
String clsName = new ClassReader(value).getClassName();

0 commit comments

Comments
 (0)