From 81eda3a33916c17e3415219a9b1e6e6295e8c748 Mon Sep 17 00:00:00 2001 From: Joe Tsai Date: Wed, 8 Feb 2023 01:57:25 -0800 Subject: [PATCH] Revert "hex: fix panic in Decode when len(src) > 2*len(dst)" This reverts CL 461958 and CL 465855. Reason for revert: This introduced an irreconcilable inconsistency with Encode Fixes #58391. Change-Id: Ifd01a04d433b24c092b73e627b8149a5851c2bca Reviewed-on: https://go-review.googlesource.com/c/go/+/469615 TryBot-Result: Gopher Robot Reviewed-by: Bryan Mills Run-TryBot: Joseph Tsai Auto-Submit: Joseph Tsai Reviewed-by: Ian Lance Taylor --- src/encoding/hex/hex.go | 3 --- src/encoding/hex/hex_test.go | 12 ------------ 2 files changed, 15 deletions(-) diff --git a/src/encoding/hex/hex.go b/src/encoding/hex/hex.go index f69abb2f7f..375f583170 100644 --- a/src/encoding/hex/hex.go +++ b/src/encoding/hex/hex.go @@ -88,9 +88,6 @@ func Decode(dst, src []byte) (int, error) { if b > 0x0f { return i, InvalidByteError(q) } - if i >= len(dst) { - return i, errors.New("encoding/hex: output buffer too small") - } dst[i] = (a << 4) | b i++ } diff --git a/src/encoding/hex/hex_test.go b/src/encoding/hex/hex_test.go index 8d1ae70774..a820fe7a15 100644 --- a/src/encoding/hex/hex_test.go +++ b/src/encoding/hex/hex_test.go @@ -55,18 +55,6 @@ func TestDecode(t *testing.T) { } } -func TestDecodeDstTooSmall(t *testing.T) { - dst := make([]byte, 1) - src := []byte{'0', '1', '2', '3'} - 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) { for i, test := range encDecTests { s := EncodeToString(test.dec) -- 2.48.1