From 62ace14fa0f20033f89ac3097f461508f2000295 Mon Sep 17 00:00:00 2001 From: Kevin Ku Date: Mon, 28 Sep 2020 15:17:44 -0700 Subject: [PATCH] commetn test --- reassembly/tcpassembly_test.go | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/reassembly/tcpassembly_test.go b/reassembly/tcpassembly_test.go index 8b76cd27d..3d3d48d1e 100644 --- a/reassembly/tcpassembly_test.go +++ b/reassembly/tcpassembly_test.go @@ -1199,13 +1199,20 @@ func TestKeepWithFlush(t *testing.T) { }) } -func TestKeepWithManualFlush(t *testing.T) { +func TestKeepWithOutOfOrderPacketAndManualFlush(t *testing.T) { makePayload := func(length int) []byte { data := make([]byte, length) rand.Read(data) return data } + // The first packet is received out of order. It contains `pageBytes + 1` + // number of bytes, so it spans 2 pages. + // The second packet carries a single byte before the first packet, and we + // request to keep `pageBytes` bytes. Then trigger a flush. + // Prior to a fix, this would result in an slice bounds out of range panic + // when the code tries to incorrectly skip the leading bytes on the second + // page of the first packet. testKeep(t, []testKeepSequence{ { tcp: layers.TCP{ @@ -1223,13 +1230,11 @@ func TestKeepWithManualFlush(t *testing.T) { Seq: 1000, BaseLayer: layers.BaseLayer{Payload: []byte{1}}, }, - keep: 3, + keep: pageBytes, want: []byte{}, flush: true, }, }) - - t.Errorf("fake error") } /*