Skip to content

Commit f30306f

Browse files
fix: update maxHeaderSize to 22 #1800 (#1877)
1 parent 328c10d commit f30306f

2 files changed

Lines changed: 23 additions & 2 deletions

File tree

structs.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ type header struct {
7272

7373
const (
7474
// Maximum possible size of the header. The maximum size of header struct will be 18 but the
75-
// maximum size of varint encoded header will be 21.
76-
maxHeaderSize = 21
75+
// maximum size of varint encoded header will be 22.
76+
maxHeaderSize = 22
7777
)
7878

7979
// Encode encodes the header into []byte. The provided []byte should be atleast 5 bytes. The

structs_test.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package badger
2+
3+
import (
4+
"math"
5+
"reflect"
6+
"testing"
7+
8+
"github.com/stretchr/testify/require"
9+
)
10+
11+
// Regression test for github.com/dgraph-io/badger/pull/1800
12+
func TestLargeEncode(t *testing.T) {
13+
var headerEnc [maxHeaderSize]byte
14+
h := header{math.MaxUint32, math.MaxUint32, math.MaxUint64, math.MaxUint8, math.MaxUint8}
15+
require.NotPanics(t, func() { _ = h.Encode(headerEnc[:]) })
16+
}
17+
18+
func TestNumFieldsHeader(t *testing.T) {
19+
// maxHeaderSize must correspond with any changes made to header
20+
require.Equal(t, 5, reflect.TypeOf(header{}).NumField())
21+
}

0 commit comments

Comments
 (0)