From 48634ceb3d7bf318c9dc524a05e2fc2870bac5c0 Mon Sep 17 00:00:00 2001 From: sashaodessa <140454972+sashaodessa@users.noreply.github.com> Date: Mon, 12 Jan 2026 12:28:26 +0100 Subject: [PATCH] Update message_test.go --- p2p/message_test.go | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/p2p/message_test.go b/p2p/message_test.go index e575c5d96e..81784723a8 100644 --- a/p2p/message_test.go +++ b/p2p/message_test.go @@ -23,6 +23,8 @@ import ( "runtime" "testing" "time" + + "github.com/ethereum/go-ethereum/rlp" ) func ExampleMsgPipe() { @@ -139,3 +141,29 @@ func TestEOFSignal(t *testing.T) { default: } } + +type msgReaderFunc func() (Msg, error) + +func (f msgReaderFunc) ReadMsg() (Msg, error) { return f() } + +func TestExpectMsgRejectsOverlongPayload(t *testing.T) { + content := []uint{1, 2, 3} + contentEnc, err := rlp.EncodeToBytes(content) + if err != nil { + t.Fatalf("rlp.EncodeToBytes failed: %v", err) + } + + r := msgReaderFunc(func() (Msg, error) { + // Payload is one byte longer than declared size. + payload := append(append([]byte(nil), contentEnc...), 0x00) + return Msg{ + Code: 7, + Size: uint32(len(contentEnc)), + Payload: bytes.NewReader(payload), + }, nil + }) + + if err := ExpectMsg(r, 7, content); err == nil { + t.Fatal("expected error for overlong payload, got nil") + } +}