1
0

follow-up prev: add testcase and minor formatting

(minor reshuffling of check so that it matches following line
 and is more clear it is a bounds check)
This commit is contained in:
SomberNight
2025-01-10 11:56:19 +00:00
parent ddb67d9bca
commit 043be2439e
2 changed files with 15 additions and 6 deletions

View File

@@ -597,7 +597,6 @@ class BCDataStream(object):
def script_GetOp(_bytes : bytes):
_bytes_len = len(_bytes)
i = 0
while i < len(_bytes):
vch = None
@@ -618,10 +617,9 @@ def script_GetOp(_bytes : bytes):
try: (nSize,) = struct.unpack_from('<I', _bytes, i)
except struct.error: raise MalformedBitcoinScript()
i += 4
if nSize > _bytes_len - i:
raise MalformedBitcoinScript(f"Push of data element that is larger than remaining data: {nSize} vs {_bytes_len - i}")
if i + nSize > len(_bytes):
raise MalformedBitcoinScript(
f"Push of data element that is larger than remaining data: {nSize} vs {len(_bytes) - i}")
vch = _bytes[i:i + nSize]
i += nSize