From 7b832a0719192eda4b92e1c53bb2d12c983c04c5 Mon Sep 17 00:00:00 2001 From: Snowhite Date: Mon, 27 Feb 2023 19:10:00 +0800 Subject: [PATCH] Returning view of method list to avoid CME The modified method `getMethodsByNameAndParamCount` is used (and only used) in the `FastHierarchy.getSignaturePolymorphicMethod` for resolving polymorphic methods. The for-loop will return the method list's iterator, but the list itself can be modified by another body pack transform thread, causing a `ConcurrentModificationException`. The patch fix the issue by returning a copy of this list. This patch also fixes the issue #1811 , and a similar issue is #1199 (fixed by #1886 ). --- src/main/java/soot/SootClass.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/soot/SootClass.java b/src/main/java/soot/SootClass.java index 4a497ce4b2b..98bc62556e4 100644 --- a/src/main/java/soot/SootClass.java +++ b/src/main/java/soot/SootClass.java @@ -1316,7 +1316,7 @@ public boolean isOpenedByModule() { */ public Collection getMethodsByNameAndParamCount(String name, int paramCount) { List result = null; - for (SootMethod m : getMethods()) { + for (SootMethod m : new ArrayList<>(getMethods())) { if (m.getParameterCount() == paramCount && m.getName().equals(name)) { if (result == null) { result = new ArrayList<>();