Skip to content

Commit

Permalink
fix: update maxHeaderSize to 22 #1800 (#1877)
Browse files Browse the repository at this point in the history
  • Loading branch information
joshua-goldstein authored Feb 19, 2023
1 parent 328c10d commit f30306f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
4 changes: 2 additions & 2 deletions structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 21 additions & 0 deletions structs_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package badger

import (
"math"
"reflect"
"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[:]) })
}

func TestNumFieldsHeader(t *testing.T) {
// maxHeaderSize must correspond with any changes made to header
require.Equal(t, 5, reflect.TypeOf(header{}).NumField())
}

0 comments on commit f30306f

Please sign in to comment.