Skip to content

Commit

Permalink
fix: stop assuming the size of field is always 1
Browse files Browse the repository at this point in the history
Signed-off-by: Kengo TODA <skypencil@gmail.com>
  • Loading branch information
KengoTODA committed Aug 28, 2022
1 parent 228eb36 commit ba1313b
Showing 1 changed file with 3 additions and 2 deletions.
Expand Up @@ -1010,6 +1010,7 @@ private boolean isPEI(InstructionHandle handle) throws CFGBuilderException {
if (ins instanceof PUTFIELD && !methodGen.isStatic()) {
// Assume that PUTFIELD on this object is not PEI
int depth = ins.consumeStack(cpg);
int fieldSize = ((PUTFIELD)ins).getFieldType(cpg).getSize();
for (InstructionHandle prev = handle.getPrev(); prev != null; prev = prev.getPrev()) {
Instruction prevInst = prev.getInstruction();
if (prevInst instanceof BranchInstruction) {
Expand All @@ -1028,10 +1029,10 @@ private boolean isPEI(InstructionHandle handle) throws CFGBuilderException {
}
}
depth = depth - prevInst.produceStack(cpg) + prevInst.consumeStack(cpg);
if (depth < 1) {
if (depth < fieldSize) {
throw new CFGBuilderException("Invalid stack at " + prev + " when checking " + handle);
}
if (depth == 1) {
if (depth == fieldSize) {
InstructionHandle prevPrev = prev.getPrev();
if (prevPrev != null && prevPrev.getInstruction() instanceof BranchInstruction) {
continue;
Expand Down

0 comments on commit ba1313b

Please sign in to comment.