What changed, and why it matters
This commit only adds a new test. It checks that the submitblock RPC command rejects block data that has extra trailing bytes after a valid block. The test confirms existing behavior rather than changing production code, so it is unlikely to be a live security fix by itself.
No immediate action required. Treat as routine test coverage. If this test was added because a real bug was found, look for a separate production-code commit that fixes the underlying issue; this commit alone does not change runtime behavior.
Security signals we found
Test verifies rejection of malformed/trailing-byte block submissions
Related to prior test for getblocktemplate proposal trailing-byte rejection
Deserialization error path is the expected safe behavior
Evidence from the diff
The diff adds TestHandleSubmitBlockRejectsTrailingBytes in rpcserver_test.go. The test constructs a submitblock command with a serialized block plus one trailing byte, calls handleSubmitBlock, and asserts that the handler returns a deserialization RPC error and a nil result before reaching the sync manager. No production code is modified.
Changed components
rpcserver_test.gosubmitblock RPC handler (test coverage only)Inspect captured patch +17 / −0
diff --git a/rpcserver_test.go b/rpcserver_test.go
index 529d76b..8ea8d18 100644
--- a/rpcserver_test.go
+++ b/rpcserver_test.go
@@ -147,6 +147,23 @@ func TestHandleGetBlockTemplateProposalRejectsTrailingBytes(t *testing.T) {
require.Nil(t, result)
}
+// TestHandleSubmitBlockRejectsTrailingBytes ensures submitblock rejects byte
+// strings that contain a valid block plus trailing data.
+func TestHandleSubmitBlockRejectsTrailingBytes(t *testing.T) {
+ t.Parallel()
+
+ defer func() {
+ recovered := recover()
+ require.Nil(t, recovered, "handler reached sync manager")
+ }()
+
+ cmd := btcjson.NewSubmitBlockCmd(blockHexWithTrailingByte(t), nil)
+ result, err := handleSubmitBlock(&rpcServer{}, cmd, make(chan struct{}))
+
+ requireRPCErrorCode(t, err, btcjson.ErrRPCDeserialization)
+ require.Nil(t, result)
+}
+
var (
// TODO(yy): make a `btctest` package and move these testing txns there
// so they be used in other tests.
Why this scored 29/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.