From 703c8ab7e5ba75c95553d4e249309297abad7102 Mon Sep 17 00:00:00 2001 From: Roland Shoemaker Date: Fri, 15 Jul 2022 10:43:44 -0700 Subject: [release-branch.go1.17] math/big: check buffer lengths in GobDecode In Float.GobDecode and Rat.GobDecode, check buffer sizes before indexing slices. Updates #53871 Fixes #54094 Change-Id: I1b652c32c2bc7a0e8aa7620f7be9b2740c568b0a Reviewed-on: https://go-review.googlesource.com/c/go/+/417774 TryBot-Result: Gopher Robot Reviewed-by: Tatiana Bradley Run-TryBot: Roland Shoemaker (cherry picked from commit 055113ef364337607e3e72ed7d48df67fde6fc66) Reviewed-on: https://go-review.googlesource.com/c/go/+/419814 Reviewed-by: Julie Qiu --- src/math/big/floatmarsh_test.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src/math/big/floatmarsh_test.go') diff --git a/src/math/big/floatmarsh_test.go b/src/math/big/floatmarsh_test.go index c056d78b80..401f45a51f 100644 --- a/src/math/big/floatmarsh_test.go +++ b/src/math/big/floatmarsh_test.go @@ -137,3 +137,15 @@ func TestFloatJSONEncoding(t *testing.T) { } } } + +func TestFloatGobDecodeShortBuffer(t *testing.T) { + for _, tc := range [][]byte{ + []byte{0x1, 0x0, 0x0, 0x0}, + []byte{0x1, 0xfa, 0x0, 0x0, 0x0, 0x0}, + } { + err := NewFloat(0).GobDecode(tc) + if err == nil { + t.Error("expected GobDecode to return error for malformed input") + } + } +} -- cgit v1.2.3-54-g00ecf