diff options
| author | Joe Tsai <joetsai@digital-static.net> | 2023-02-06 14:48:19 -0800 |
|---|---|---|
| committer | Gopher Robot <gobot@golang.org> | 2023-02-07 15:37:55 +0000 |
| commit | f02cdba16398cee70a69262a55eb357dac6f81df (patch) | |
| tree | 934cb82023f14a50a02977af40da542fc88aec2a /src/encoding/hex/hex_test.go | |
| parent | 02d8ebda8398342516a24a3e8435d527ed156cab (diff) | |
| download | go-f02cdba16398cee70a69262a55eb357dac6f81df.tar.xz | |
encoding/hex: fix Decode output check regression
CL 461958 fixed a potential panic,
but also introduced an observable regression where
invalid input could be detected before the panic occurs.
Adjust the check to preserve prior behavior,
while also preventing the panic.
Change-Id: I52819f88a6a64883fbc9fd512697c38c29ca0ccd
Reviewed-on: https://go-review.googlesource.com/c/go/+/465855
Auto-Submit: Joseph Tsai <joetsai@digital-static.net>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Bryan Mills <bcmills@google.com>
Run-TryBot: Joseph Tsai <joetsai@digital-static.net>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Diffstat (limited to 'src/encoding/hex/hex_test.go')
| -rw-r--r-- | src/encoding/hex/hex_test.go | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/src/encoding/hex/hex_test.go b/src/encoding/hex/hex_test.go index 1eb169cdee..8d1ae70774 100644 --- a/src/encoding/hex/hex_test.go +++ b/src/encoding/hex/hex_test.go @@ -55,13 +55,16 @@ func TestDecode(t *testing.T) { } } -func TestDecode_tooFewDstBytes(t *testing.T) { +func TestDecodeDstTooSmall(t *testing.T) { dst := make([]byte, 1) src := []byte{'0', '1', '2', '3'} - _, err := Decode(dst, src) + n, err := Decode(dst, src) if err == nil { t.Errorf("expected Decode to return an error, but it returned none") } + if !bytes.Equal(dst[:n], []byte{0x01}) { + t.Errorf("output mismatch: got %x, want 01", dst[:n]) + } } func TestEncodeToString(t *testing.T) { |
