From e137b83f322a4ea1ae5c2f7e87e1e88a60d154cf Mon Sep 17 00:00:00 2001 From: Joshua Goldstein Date: Fri, 17 Feb 2023 09:04:26 -0600 Subject: [PATCH 1/8] update maxheadersize --- structs.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/structs.go b/structs.go index f51c4a655..7a06d4f13 100644 --- a/structs.go +++ b/structs.go @@ -72,8 +72,8 @@ type header struct { const ( // Maximum possible size of the header. The maximum size of header struct will be 18 but the - // maximum size of varint encoded header will be 21. - maxHeaderSize = 21 + // maximum size of varint encoded header will be 22. + maxHeaderSize = 22 ) // Encode encodes the header into []byte. The provided []byte should be atleast 5 bytes. The From fbe78e4febde0b7519359a3c3273aed2ae2d790c Mon Sep 17 00:00:00 2001 From: Joshua Goldstein Date: Sat, 18 Feb 2023 11:15:00 -0600 Subject: [PATCH 2/8] add test --- structs_test.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 structs_test.go diff --git a/structs_test.go b/structs_test.go new file mode 100644 index 000000000..c0ee1ba8e --- /dev/null +++ b/structs_test.go @@ -0,0 +1,17 @@ +package badger + +import ( + "math" + "testing" + + "github.com/stretchr/testify/require" +) + +// Regression test for github.com/dgraph-io/badger/pull/1800 +func TestLargeEncode(t *testing.T) { + + var headerEnc [maxHeaderSize]byte + h := header{math.MaxUint32, math.MaxUint32, math.MaxUint64, math.MaxUint8, math.MaxUint8} + require.NotPanics(t, func() { _ = h.Encode(headerEnc[:]) }) + +} From 938998c707fb428008b40c15f56ef4b27d5e2442 Mon Sep 17 00:00:00 2001 From: Joshua Goldstein Date: Sat, 18 Feb 2023 11:58:58 -0600 Subject: [PATCH 3/8] test header size 20 --- structs.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/structs.go b/structs.go index 7a06d4f13..0430d8cd3 100644 --- a/structs.go +++ b/structs.go @@ -73,7 +73,7 @@ type header struct { const ( // Maximum possible size of the header. The maximum size of header struct will be 18 but the // maximum size of varint encoded header will be 22. - maxHeaderSize = 22 + maxHeaderSize = 20 ) // Encode encodes the header into []byte. The provided []byte should be atleast 5 bytes. The From 688ef4647a366e7e07997741d8e54232d2215486 Mon Sep 17 00:00:00 2001 From: Joshua Goldstein Date: Sat, 18 Feb 2023 12:08:54 -0600 Subject: [PATCH 4/8] temp modify test --- structs_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/structs_test.go b/structs_test.go index c0ee1ba8e..b8a9f4fdb 100644 --- a/structs_test.go +++ b/structs_test.go @@ -11,7 +11,7 @@ import ( func TestLargeEncode(t *testing.T) { var headerEnc [maxHeaderSize]byte - h := header{math.MaxUint32, math.MaxUint32, math.MaxUint64, math.MaxUint8, math.MaxUint8} + h := header{math.MaxUint16, math.MaxUint32, math.MaxUint64, math.MaxUint8, math.MaxUint8} require.NotPanics(t, func() { _ = h.Encode(headerEnc[:]) }) } From 2d48289eab617b4ec6356cffd4855eebe5f7af3b Mon Sep 17 00:00:00 2001 From: Joshua Goldstein <92491720+joshua-goldstein@users.noreply.github.com> Date: Sun, 19 Feb 2023 09:23:48 -0600 Subject: [PATCH 5/8] Update structs.go --- structs.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/structs.go b/structs.go index 0430d8cd3..7a06d4f13 100644 --- a/structs.go +++ b/structs.go @@ -73,7 +73,7 @@ type header struct { const ( // Maximum possible size of the header. The maximum size of header struct will be 18 but the // maximum size of varint encoded header will be 22. - maxHeaderSize = 20 + maxHeaderSize = 22 ) // Encode encodes the header into []byte. The provided []byte should be atleast 5 bytes. The From b5458a497883b731f2f8efeccca2001760b4ea1e Mon Sep 17 00:00:00 2001 From: Joshua Goldstein <92491720+joshua-goldstein@users.noreply.github.com> Date: Sun, 19 Feb 2023 09:24:04 -0600 Subject: [PATCH 6/8] Update structs_test.go --- structs_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/structs_test.go b/structs_test.go index b8a9f4fdb..c0ee1ba8e 100644 --- a/structs_test.go +++ b/structs_test.go @@ -11,7 +11,7 @@ import ( func TestLargeEncode(t *testing.T) { var headerEnc [maxHeaderSize]byte - h := header{math.MaxUint16, math.MaxUint32, math.MaxUint64, math.MaxUint8, math.MaxUint8} + h := header{math.MaxUint32, math.MaxUint32, math.MaxUint64, math.MaxUint8, math.MaxUint8} require.NotPanics(t, func() { _ = h.Encode(headerEnc[:]) }) } From d80ee760dcd4d897035f8bba1f5900e0649d8816 Mon Sep 17 00:00:00 2001 From: Joshua Goldstein Date: Sun, 19 Feb 2023 09:43:41 -0600 Subject: [PATCH 7/8] add test for num fields in header --- structs_test.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/structs_test.go b/structs_test.go index c0ee1ba8e..c9a8a450c 100644 --- a/structs_test.go +++ b/structs_test.go @@ -2,6 +2,7 @@ package badger import ( "math" + "reflect" "testing" "github.com/stretchr/testify/require" @@ -15,3 +16,10 @@ func TestLargeEncode(t *testing.T) { require.NotPanics(t, func() { _ = h.Encode(headerEnc[:]) }) } + +func TestNumFieldsHeader(t *testing.T) { + + // maxHeaderSize must correspond with any changes made to header + require.Equal(t, 5, reflect.TypeOf(header{}).NumField()) + +} From 8faa5a9c833d417dd8a49a3e15754adbd8515aca Mon Sep 17 00:00:00 2001 From: Joshua Goldstein Date: Sun, 19 Feb 2023 09:44:24 -0600 Subject: [PATCH 8/8] spacing --- structs_test.go | 4 ---- 1 file changed, 4 deletions(-) diff --git a/structs_test.go b/structs_test.go index c9a8a450c..4d3cc3839 100644 --- a/structs_test.go +++ b/structs_test.go @@ -10,16 +10,12 @@ import ( // Regression test for github.com/dgraph-io/badger/pull/1800 func TestLargeEncode(t *testing.T) { - var headerEnc [maxHeaderSize]byte h := header{math.MaxUint32, math.MaxUint32, math.MaxUint64, math.MaxUint8, math.MaxUint8} require.NotPanics(t, func() { _ = h.Encode(headerEnc[:]) }) - } func TestNumFieldsHeader(t *testing.T) { - // maxHeaderSize must correspond with any changes made to header require.Equal(t, 5, reflect.TypeOf(header{}).NumField()) - }