diff options
| author | Johan Abildskov <randomsort@gmail.com> | 2023-03-22 06:31:25 +0000 |
|---|---|---|
| committer | Gopher Robot <gobot@golang.org> | 2023-03-23 17:32:41 +0000 |
| commit | 3d5391ed87d813110e10b954c62bf7ed578b591f (patch) | |
| tree | cf48d8b3303b187cab288d68896aa13ab4588cec /src/encoding | |
| parent | 1596d71255f3c19a27600e751592079dae46bf40 (diff) | |
| download | go-3d5391ed87d813110e10b954c62bf7ed578b591f.tar.xz | |
encoding/gob: extend partially allocated string slices
Fixes #59172
Change-Id: I54d5e724f10117a40ec5dd58c810f6bbb2475933
GitHub-Last-Rev: d1a986698c820415b2e0be12141091a3cbf6fde3
GitHub-Pull-Request: golang/go#59173
Reviewed-on: https://go-review.googlesource.com/c/go/+/478215
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Rob Pike <r@golang.org>
Run-TryBot: Ian Lance Taylor <iant@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Ian Lance Taylor <iant@google.com>
Reviewed-by: Heschi Kreinick <heschi@google.com>
Diffstat (limited to 'src/encoding')
| -rw-r--r-- | src/encoding/gob/codec_test.go | 14 | ||||
| -rw-r--r-- | src/encoding/gob/dec_helpers.go | 3 |
2 files changed, 17 insertions, 0 deletions
diff --git a/src/encoding/gob/codec_test.go b/src/encoding/gob/codec_test.go index 54c356c464..28cd6088af 100644 --- a/src/encoding/gob/codec_test.go +++ b/src/encoding/gob/codec_test.go @@ -1544,6 +1544,10 @@ type LargeSliceStruct struct { S []StringPair } +type LargeSliceString struct { + S []string +} + func testEncodeDecode(t *testing.T, in, out any) { t.Helper() var b bytes.Buffer @@ -1592,4 +1596,14 @@ func TestLargeSlice(t *testing.T) { rt := &LargeSliceStruct{} testEncodeDecode(t, st, rt) }) + t.Run("string", func(t *testing.T) { + t.Parallel() + s := make([]string, 1<<21) + for i := range s { + s[i] = string(rune(i)) + } + st := &LargeSliceString{S: s} + rt := &LargeSliceString{} + testEncodeDecode(t, st, rt) + }) } diff --git a/src/encoding/gob/dec_helpers.go b/src/encoding/gob/dec_helpers.go index a09ac8fc1a..098ba7254a 100644 --- a/src/encoding/gob/dec_helpers.go +++ b/src/encoding/gob/dec_helpers.go @@ -358,6 +358,9 @@ func decStringSlice(state *decoderState, v reflect.Value, length int, ovfl error if state.b.Len() == 0 { errorf("decoding string array or slice: length exceeds input size (%d elements)", length) } + if i >= len(slice) { + growSlice(v, &slice, length) + } u := state.decodeUint() n := int(u) if n < 0 || uint64(n) != u || n > state.b.Len() { |
