Fixed #1904 NullpointerException when renaming invalid identifiers in AS1/2 files caused by missing charset

This commit is contained in:
Jindra Petřík
2022-12-20 08:55:15 +01:00
parent d5d730b083
commit ce4f3e2920
7 changed files with 23 additions and 8 deletions

View File

@@ -2968,7 +2968,11 @@ public final class SWF implements SWFContainerItem, Timelined, Openable {
for (ASMSource src : actionsMap.keySet()) {
actionsMap.get(src).removeNops();
src.setActions(actionsMap.get(src));
try {
src.setActions(actionsMap.get(src));
} catch (ValueTooLargeException vtle) {
Logger.getLogger(SWF.class.getName()).log(Level.WARNING, "renaming AS2 identifiers failed for an action source with error: {0}", vtle.getMessage());
}
src.setModified();
}

View File

@@ -93,6 +93,11 @@ public class ActionGraph extends Graph {
this.insideDoInitAction = insideDoInitAction;
this.insideFunction = insideFunction;
}
@Override
public ActionGraphSource getGraphCode() {
return (ActionGraphSource) code;
}
@Override
public LinkedHashMap<String, Graph> getSubGraphs() {
@@ -110,7 +115,7 @@ public class ActionGraph extends Graph {
outs.add(new ActionList(((ActionGraphSource) code).getCharset()));
continue;
}
outs.add(new ActionList(alist.subList(adr2ip(alist, endAddr), adr2ip(alist, endAddr + size))));
outs.add(new ActionList(alist.subList(adr2ip(alist, endAddr), adr2ip(alist, endAddr + size)), getGraphCode().getCharset()));
endAddr += size;
}

View File

@@ -60,7 +60,7 @@ public class ActionGraphSource extends GraphSource {
}
public ActionGraphSource(String path, boolean insideDoInitAction, List<Action> actions, int version, HashMap<Integer, String> registerNames, HashMap<String, GraphTargetItem> variables, HashMap<String, GraphTargetItem> functions, String charset) {
this.actions = actions instanceof ActionList ? (ActionList) actions : new ActionList(actions);
this.actions = actions instanceof ActionList ? (ActionList) actions : new ActionList(actions, charset);
this.version = version;
this.registerNames = registerNames;
this.variables = variables;

View File

@@ -63,8 +63,9 @@ public class ActionList extends ArrayList<Action> {
}
public ActionList(Collection<Action> actions) {
public ActionList(Collection<Action> actions, String charset) {
super(actions);
this.charset = charset;
}
public void setActions(List<Action> list) {

View File

@@ -139,7 +139,7 @@ public class ActionListReader {
nextOffsets.put(endAddress, endAddress + 1);
}
ActionList actions = fixActionList(new ActionList(actionMap.values()), nextOffsets);
ActionList actions = fixActionList(new ActionList(actionMap.values(), sis.getCharset()), nextOffsets);
// jump to the entry action when it is diffrent from the first action in the map
if (entryAction != actions.get(0)) {

View File

@@ -597,7 +597,7 @@ public class FastActionList implements Collection<ActionItem> {
List<Action> resultList = new ArrayList<>(size);
ActionItem item = firstItem;
if (item == null) {
return new ActionList(resultList);
return new ActionList(resultList, charset);
}
do {
@@ -605,7 +605,7 @@ public class FastActionList implements Collection<ActionItem> {
item = item.next;
} while (item != firstItem);
ActionList result = new ActionList(resultList);
ActionList result = new ActionList(resultList, charset);
updateActionAddressesAndLengths();
updateJumps();
updateActionStores();