]> Cypherpunks.ru repositories - gostls13.git/commitdiff
Revert "hex: fix panic in Decode when len(src) > 2*len(dst)"
authorJoe Tsai <joetsai@digital-static.net>
Wed, 8 Feb 2023 09:57:25 +0000 (01:57 -0800)
committerGopher Robot <gobot@golang.org>
Tue, 21 Feb 2023 15:35:11 +0000 (15:35 +0000)
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 <gobot@golang.org>
Reviewed-by: Bryan Mills <bcmills@google.com>
Run-TryBot: Joseph Tsai <joetsai@digital-static.net>
Auto-Submit: Joseph Tsai <joetsai@digital-static.net>
Reviewed-by: Ian Lance Taylor <iant@google.com>
src/encoding/hex/hex.go
src/encoding/hex/hex_test.go

index f69abb2f7fea766c6b0bcc55dee73491b62a89ca..375f5831709bb7764f73f909c541bb7830bacc0a 100644 (file)
@@ -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++
        }
index 8d1ae7077443f3435bbd5a9127642dd973829fa1..a820fe7a1514f7533e32d9d67830a23dced05361 100644 (file)
@@ -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)