Skip to content

Commit 81eda3a

Browse files
dsnetgopherbot
authored andcommitted
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 <[email protected]> Reviewed-by: Bryan Mills <[email protected]> Run-TryBot: Joseph Tsai <[email protected]> Auto-Submit: Joseph Tsai <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]>
1 parent 7f59bea commit 81eda3a

File tree

2 files changed

+0
-15
lines changed

2 files changed

+0
-15
lines changed

src/encoding/hex/hex.go

-3
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,6 @@ func Decode(dst, src []byte) (int, error) {
8888
if b > 0x0f {
8989
return i, InvalidByteError(q)
9090
}
91-
if i >= len(dst) {
92-
return i, errors.New("encoding/hex: output buffer too small")
93-
}
9491
dst[i] = (a << 4) | b
9592
i++
9693
}

src/encoding/hex/hex_test.go

-12
Original file line numberDiff line numberDiff line change
@@ -55,18 +55,6 @@ func TestDecode(t *testing.T) {
5555
}
5656
}
5757

58-
func TestDecodeDstTooSmall(t *testing.T) {
59-
dst := make([]byte, 1)
60-
src := []byte{'0', '1', '2', '3'}
61-
n, err := Decode(dst, src)
62-
if err == nil {
63-
t.Errorf("expected Decode to return an error, but it returned none")
64-
}
65-
if !bytes.Equal(dst[:n], []byte{0x01}) {
66-
t.Errorf("output mismatch: got %x, want 01", dst[:n])
67-
}
68-
}
69-
7058
func TestEncodeToString(t *testing.T) {
7159
for i, test := range encDecTests {
7260
s := EncodeToString(test.dec)

0 commit comments

Comments
 (0)