From 86a91539b8acd322800b10db3d64ce42d43dfcde Mon Sep 17 00:00:00 2001 From: Nigel Tao Date: Tue, 1 May 2012 14:28:33 +1000 Subject: [PATCH] compress/flate: add a copy overrun test. R=rsc, r CC=golang-dev https://golang.org/cl/6143043 --- src/pkg/compress/flate/copy_test.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/pkg/compress/flate/copy_test.go b/src/pkg/compress/flate/copy_test.go index d13941cf1c0..a9281d446e9 100644 --- a/src/pkg/compress/flate/copy_test.go +++ b/src/pkg/compress/flate/copy_test.go @@ -29,7 +29,7 @@ func TestForwardCopy(t *testing.T) { {0, 0, 0, 0, ""}, } for _, tc := range testCases { - b := []byte("012345678") + b := []byte("0123456789") dst := b[tc.dst0:tc.dst1] src := b[tc.src0:tc.src1] n := forwardCopy(dst, src) @@ -38,5 +38,15 @@ func TestForwardCopy(t *testing.T) { t.Errorf("dst=b[%d:%d], src=b[%d:%d]: got %q, want %q", tc.dst0, tc.dst1, tc.src0, tc.src1, got, tc.want) } + // Check that the bytes outside of dst[:n] were not modified. + for i, x := range b { + if i >= tc.dst0 && i < tc.dst0+n { + continue + } + if int(x) != '0'+i { + t.Errorf("dst=b[%d:%d], src=b[%d:%d]: copy overrun at b[%d]: got '%c', want '%c'", + tc.dst0, tc.dst1, tc.src0, tc.src1, i, x, '0'+i) + } + } } }