Skip to content

Commit 5feefbe

Browse files
committed
Improve asmap Interpret checks and document failures
1 parent 2b3dbfa commit 5feefbe

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/util/asmap.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,18 +91,18 @@ uint32_t Interpret(const std::vector<bool> &asmap, const std::vector<bool> &ip)
9191
} else if (opcode == Instruction::JUMP) {
9292
jump = DecodeJump(pos, endpos);
9393
if (jump == INVALID) break; // Jump offset straddles EOF
94-
if (bits == 0) break;
94+
if (bits == 0) break; // No input bits left
95+
if (jump >= endpos - pos) break; // Jumping past EOF
9596
if (ip[ip.size() - bits]) {
96-
if (jump >= endpos - pos) break;
9797
pos += jump;
9898
}
9999
bits--;
100100
} else if (opcode == Instruction::MATCH) {
101101
match = DecodeMatch(pos, endpos);
102102
if (match == INVALID) break; // Match bits straddle EOF
103103
matchlen = CountBits(match) - 1;
104+
if (bits < matchlen) break; // Not enough input bits
104105
for (uint32_t bit = 0; bit < matchlen; bit++) {
105-
if (bits == 0) break;
106106
if ((ip[ip.size() - bits]) != ((match >> (matchlen - 1 - bit)) & 1)) {
107107
return default_asn;
108108
}
@@ -115,5 +115,6 @@ uint32_t Interpret(const std::vector<bool> &asmap, const std::vector<bool> &ip)
115115
break; // Instruction straddles EOF
116116
}
117117
}
118+
// Reached EOF without RETURN, or aborted (see any of the breaks above).
118119
return 0; // 0 is not a valid ASN
119120
}

0 commit comments

Comments
 (0)