Skip to content

Commit

Permalink
fix: Improve detection of red-herring junk data masquarading as class…
Browse files Browse the repository at this point in the history
…es due to conflicting zip file entries
  • Loading branch information
Col-E committed Apr 16, 2021
1 parent b63aa8c commit ff244dd
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 8 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.19.2</version>
<version>2.19.3</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.19.2";
public static final String VERSION = "2.19.3";
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
33 changes: 27 additions & 6 deletions src/main/java/me/coley/recaf/workspace/EntryLoader.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package me.coley.recaf.workspace;

import me.coley.cafedude.InvalidClassException;
import me.coley.cafedude.io.ClassFileReader;
import me.coley.recaf.plugin.PluginsManager;
import me.coley.recaf.plugin.api.LoadInterceptorPlugin;
import me.coley.recaf.util.ClassUtil;
Expand All @@ -24,6 +26,7 @@ public class EntryLoader {
private final Map<String, byte[]> classes = new HashMap<>();
private final Map<String, byte[]> files = new HashMap<>();
private final Map<String, byte[]> invalidClasses = new HashMap<>();
private final Map<String, byte[]> invalidJunkClasses = new HashMap<>();

/**
* @return New archive entry loader instance.
Expand Down Expand Up @@ -52,14 +55,32 @@ public static EntryLoader create() {
public boolean onClass(String entryName, byte[] value) {
// Check if class is valid. If it is not it will be stored for later.
if (!ClassUtil.isValidClass(value)) {
if (invalidClasses.containsKey(entryName)) {
debug("Skipping duplicate invalid class '{}'", entryName);
try {
// If the data can be read, overwrite whatever entry we have previously seen
new ClassFileReader().read(value);
invalidClasses.put(entryName, value);
if (invalidJunkClasses.remove(entryName) != null) {
debug("Replacing class '{}' previously associated with non-class junk with" +
" newly discovered class data", entryName);
}
return false;
} catch (InvalidClassException e) {
// Skip if we think this is junk data that is masking an invalid class we already recovered
if (invalidClasses.containsKey(entryName)) {
debug("Skipping masking junk data for class '{}'", entryName);
return false;
}
// Doesnt look like the CAFEDOOD backup parser can read it either.
if (invalidJunkClasses.containsKey(entryName)) {
// Already seen it. Probably dupe junk data.
debug("Skipping duplicate invalid class '{}'", entryName);
return false;
} else {
debug("Invalid class detected, not parsable by backup reader \"{}\"", entryName);
}
invalidJunkClasses.put(entryName, value);
return false;
} else {
debug("Invalid class detected \"{}\"", entryName);
}
invalidClasses.put(entryName, value);
return false;
}
// Check if we've already seen this class
String clsName = new ClassReader(value).getClassName();
Expand Down

0 comments on commit ff244dd

Please sign in to comment.