AS2 parser: add string to constant pool, if there is enough space

This commit is contained in:
honfika@gmail.com
2015-07-18 21:00:32 +02:00
parent cc4a5b7d82
commit 1aa9504240
2 changed files with 14 additions and 2 deletions

View File

@@ -1810,9 +1810,17 @@ public class ActionScript2Parser {
private DirectValueActionItem pushConst(String s) throws IOException, ActionParseException {
int index = constantPool.indexOf(s);
if (index == -1) {
constantPool.add(s);
index = constantPool.indexOf(s);
if (ActionConstantPool.calculateSize(constantPool) + ActionConstantPool.calculateSize(s) <= 0xffff) {
// constant pool is not full
constantPool.add(s);
index = constantPool.indexOf(s);
}
}
if (index == -1) {
return new DirectValueActionItem(null, 0, s, constantPool);
}
return new DirectValueActionItem(null, 0, new ConstantIndex(index), constantPool);
}

View File

@@ -80,6 +80,10 @@ public class ActionConstantPool extends Action {
return calculateSize(constantPool);
}
public static int calculateSize(String str) {
return Utf8Helper.getBytesLength(str) + 1;
}
public static int calculateSize(List<String> strings) {
int res = 2;
for (String s : strings) {