diff options
| author | Andy Pan <panjf2000@gmail.com> | 2023-08-18 13:39:57 +0800 |
|---|---|---|
| committer | Gopher Robot <gobot@golang.org> | 2023-08-19 23:03:14 +0000 |
| commit | ba626ac327f45a6d9d211fddd5b48e321fa0702a (patch) | |
| tree | e19a50997936bcf46f8d85de099a39a40a8e48b3 /src/encoding/gob/codec_test.go | |
| parent | 7b2f81eb3b19232c1d3a60241cb92c1c50d0e4ab (diff) | |
| download | go-ba626ac327f45a6d9d211fddd5b48e321fa0702a.tar.xz | |
encoding/gob: prevent panic from index out of range in Decoder.typeString
I believe this bug is introduced by CL 460543 which optimizes the allocations
by changing the type of `idToType` from map to slice, but didn't update the
access code in `Decoder.typeString` that is safe for map but not for slice.
Fixes #62117
Change-Id: I0f2e4cc2f34c54dada1f83458ba512a6fde6dcbe
Reviewed-on: https://go-review.googlesource.com/c/go/+/520757
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
Run-TryBot: Andy Pan <panjf2000@gmail.com>
Auto-Submit: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Daniel Martà <mvdan@mvdan.cc>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Run-TryBot: Ian Lance Taylor <iant@google.com>
Diffstat (limited to 'src/encoding/gob/codec_test.go')
| -rw-r--r-- | src/encoding/gob/codec_test.go | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/src/encoding/gob/codec_test.go b/src/encoding/gob/codec_test.go index 11a38f5f58..ec56ad50b2 100644 --- a/src/encoding/gob/codec_test.go +++ b/src/encoding/gob/codec_test.go @@ -1616,3 +1616,15 @@ func TestLargeSlice(t *testing.T) { testEncodeDecode(t, st, rt) }) } + +func TestLocalRemoteTypesMismatch(t *testing.T) { + // Test data is from https://go.dev/issue/62117. + testData := []byte{9, 127, 3, 1, 2, 255, 128, 0, 0, 0, 3, 255, 128, 0} + + var v []*struct{} + buf := bytes.NewBuffer(testData) + err := NewDecoder(buf).Decode(&v) + if err == nil { + t.Error("Encode/Decode: expected error but got err == nil") + } +} |
