Saving only modified ABC body code

Reading ABC code outside bounds fix
This commit is contained in:
Jindra Petřík
2014-09-24 17:42:44 +02:00
parent 92162124f5
commit f202a81ddc
5 changed files with 27 additions and 10 deletions

View File

@@ -545,7 +545,7 @@ public class ABC {
mb.init_scope_depth = ais.readU30("init_scope_depth");
mb.max_scope_depth = ais.readU30("max_scope_depth");
int code_length = ais.readU30("code_length");
mb.codeBytes = ais.readBytes(code_length, "code");
mb.setCodeBytes(ais.readBytes(code_length, "code"));
int ex_count = ais.readU30("ex_count");
mb.exceptions = new ABCException[ex_count];
for (int j = 0; j < ex_count; j++) {
@@ -668,7 +668,7 @@ public class ABC {
aos.writeU30(mb.max_regs);
aos.writeU30(mb.init_scope_depth);
aos.writeU30(mb.max_scope_depth);
byte[] codeBytes = mb.getCode().getBytes();
byte[] codeBytes = mb.getCodeBytes();
aos.writeU30(codeBytes.length);
aos.write(codeBytes);
aos.writeU30(mb.exceptions.length);

View File

@@ -788,12 +788,18 @@ public class AVM2Code implements Cloneable {
Map<Long, AVM2Instruction> codeMap = new TreeMap<>();
DumpInfo diParent = ais.dumpInfo;
List<Long> addresses = new ArrayList<>();
addresses.add(ais.getPosition());
long startPos = ais.getPosition();
addresses.add(startPos);
while (!addresses.isEmpty()) {
long address = addresses.remove(0);
if (codeMap.containsKey(address)) {
continue;
}
if(address<startPos) //no jump outside block
{
continue;
}
try {
ais.seek(address);
while (ais.available() > 0) {

View File

@@ -54,13 +54,26 @@ public class MethodBody implements Cloneable {
public int max_regs;
public int init_scope_depth;
public int max_scope_depth;
public byte[] codeBytes;
private byte[] codeBytes = new byte[0];
private AVM2Code code;
public ABCException[] exceptions = new ABCException[0];
public Traits traits = new Traits();
public transient List<GraphTargetItem> convertedItems;
public transient Throwable convertException;
public synchronized void setCodeBytes(byte codeBytes[]){
this.codeBytes = codeBytes;
this.code = null;
}
public synchronized byte[] getCodeBytes() {
if(code == null){
return codeBytes;
}else{
return code.getBytes();
}
}
public synchronized AVM2Code getCode() {
if (code == null) {
AVM2Code avm2Code;