Repository navigation
Conversation
TestScriptTokenizer began with an unconditional t.Skip(), leaving the
core script tokenizer parser without direct coverage.
The test is ported from Decred and uses the "0xHH{N}" short-form repeat
syntax (e.g. "0x01{76}" for 76 bytes of 0x01), which parseShortForm did
not support, so simply removing the skip panicked in mustParseShortForm
with 'bad token "0x01{76}"'. The tokenizer itself was never the problem;
the test helper was.
Extend parseHex to recognise the optional "{N}" repeat suffix and repeat
the decoded bytes N times, then drop the t.Skip() so the tokenizer test
actually runs.
fametrano
left a comment
There was a problem hiding this comment.
tACK 2739f15
go test and go vet pass on txscript at the head. I applied these tests to 8b70634, just before PR #1769 added the empty sigScript check. There the P2SH case panics with the slice bounds out of range [1:0] from ISS #1508, and with the fix it passes. This supports closing ISS #1508. At the head, finalOpcodeData already handles an empty script, so the length check is redundant; the test guards against the old sigScript[1:] coming back. With only the skip removed, TestScriptTokenizer panics on master because parseHex cannot read 0x01{76}. Commands and output: https://gist.github.com/fametrano/f572a177d7aaa389a7a0aca35d58de05/13224e8c58cfc5fd6e7f7ef16a68095d62ebb0b7
Not blocking: the P2WSH empty witness case also passes before the fix, because getWitnessSigOps already checked len(witness) > 0 in v0.20.1-beta, so it is not a variant of ISS #1508 as its comment says. Three added lines run past 80 columns.
|
Thanks for the careful review and tACK — and for independently reproducing the issue #1508 panic against 8b70634 before the fix. That's exactly the confirmation this was meant to lock in. Both of your non-blocking notes are addressed in 12655e2:
No functional change — |
fametrano
left a comment
There was a problem hiding this comment.
tACK 12655e2
The new commit changes only comments, a test name and line wraps, and no added line now runs past 80 columns. I ran the same script against this head, with only its sha and the pattern for the renamed P2SH case changed: on 8b70634 the P2SH case still panics with slice bounds out of range [1:0], with PR #1769 it passes, and go test and go vet pass on txscript. Commands and output: https://gist.github.com/fametrano/f572a177d7aaa389a7a0aca35d58de05/a77dcdf8fb8e90f465e7ad2064d0b7a0313ce204
Not blocking: the new P2WSH comment and the commit message say GetWitnessSigOpCount guards the empty witness, but the len(witness) > 0 check is in getWitnessSigOps, which it calls.
|
Good catch, and you're right — the |
allocz
left a comment
There was a problem hiding this comment.
Last two commits can be squashed, right? Code looks good, tests passing.
…anic Issue btcsuite#1508 reported a "slice bounds out of range [1:0]" panic in GetWitnessSigOpCount, reachable from the mempool during transaction acceptance, when counting signature operations for a spend whose signature script was empty on the nested-p2sh branch. Current master already guards that path (len(sigScript) > 0 in the nested-p2sh branch). Add table cases to TestGetWitnessSigOpCount that reproduce the historical input - an empty signature script against a P2SH pkScript with no witness - so the panic cannot silently regress; it now counts 0 sig ops without panicking. Also add a bare P2WSH pkScript with an empty witness stack. That path was never a btcsuite#1508 crash variant - getWitnessSigOps guards for a non-empty witness before indexing, so it never panicked - and the case only pins its expected sig op count of 0.
12655e2 to
149a632
Compare
|
Done — squashed the two #1508 test commits into one ( |
Two test-only improvements to
txscript— no production or consensus code is changed.1. Re-enable
TestScriptTokenizerTestScriptTokenizerbegan with an unconditionalt.Skip(), so the scripttokenizer — a core untrusted-input parser — had no coverage. The skip was there
because the test (ported from Decred) uses the
0xHH{N}repeat short-form,which
parseShortForm'sparseHexhelper didn't support. This extendsparseHexto handle the{N}repeat suffix and removes thet.Skip(). Thetokenizer itself was never the issue — only the test helper — and all cases now
pass.
2. Regression tests for issue #1508
Issue #1508 ("slice bounds out of range [1:0] in
GetWitnessSigOpCount",reachable from the mempool) is already fixed on master — both
GetWitnessSigOpCountandgetWitnessSigOpsnow guard their length checksbefore indexing. This adds two table cases to
TestGetWitnessSigOpCountthatexercise the exact historical inputs (empty sigScript + P2SH pkScript + no
witness; and a P2WSH pkScript + empty witness), locking the fix against
regression.
Verification
TestScriptTokenizer: skipped/panicked before, passes after.TestGetWitnessSigOpCount: passes on master; temporarily removing the guardsmakes the new cases panic, and restoring them passes — confirming they
genuinely lock the fix.
cd txscript && go test ./...green;go vet ./...clean.