@@ -282,6 +282,7 @@ func (i *PrefixBytesIter) Init(maxKeyLength int, syntheticPrefix block.Synthetic
282282func (b * PrefixBytes ) SetAt (it * PrefixBytesIter , i int ) {
283283 // Determine the offset and length of the bundle prefix.
284284 bundleOffsetIndex := b .bundleOffsetIndexForRow (i )
285+ invariants .CheckBounds (bundleOffsetIndex , b .rawBytes .slices )
285286 bundleOffsetStart , bundleOffsetEnd := b .rawBytes .offsets .At2 (bundleOffsetIndex )
286287 bundlePrefixLen := bundleOffsetEnd - bundleOffsetStart
287288
@@ -329,6 +330,7 @@ func (b *PrefixBytes) SetNext(it *PrefixBytesIter) {
329330 // If the next row is in the same bundle, we can take a fast path of only
330331 // updating the per-row suffix.
331332 if it .offsetIndex < it .nextBundleOffsetIndex {
333+ invariants .CheckBounds (it .offsetIndex , b .rawBytes .slices )
332334 rowSuffixStart , rowSuffixEnd := b .rawBytes .offsets .At2 (it .offsetIndex )
333335 rowSuffixLen := rowSuffixEnd - rowSuffixStart
334336 if rowSuffixLen == 0 {
@@ -351,6 +353,7 @@ func (b *PrefixBytes) SetNext(it *PrefixBytesIter) {
351353 // The offsetIndex is currently pointing to the start of the new bundle
352354 // prefix. Increment it to point at the start of the new row suffix.
353355 it .offsetIndex ++
356+ invariants .CheckBounds (it .offsetIndex , b .rawBytes .slices )
354357 rowSuffixStart , rowSuffixEnd := b .rawBytes .offsets .At2 (it .offsetIndex )
355358 rowSuffixLen := rowSuffixEnd - rowSuffixStart
356359
@@ -391,15 +394,17 @@ func (b *PrefixBytes) SharedPrefix() []byte {
391394// prefix for the column. The returned slice should not be mutated.
392395func (b * PrefixBytes ) RowBundlePrefix (row int ) []byte {
393396 i := b .bundleOffsetIndexForRow (row )
394- return b .rawBytes .slice (b .rawBytes .offsets .At (i ), b .rawBytes .offsets .At (i + 1 ))
397+ invariants .CheckBounds (i , b .rawBytes .slices )
398+ return b .rawBytes .slice (b .rawBytes .offsets .At2 (i ))
395399}
396400
397401// BundlePrefix returns the prefix of the i-th bundle in the column. The
398402// provided i must be in the range [0, BundleCount()). The returned slice should
399403// not be mutated.
400404func (b * PrefixBytes ) BundlePrefix (i int ) []byte {
401405 j := b .offsetIndexByBundleIndex (i )
402- return b .rawBytes .slice (b .rawBytes .offsets .At (j ), b .rawBytes .offsets .At (j + 1 ))
406+ invariants .CheckBounds (j , b .rawBytes .slices )
407+ return b .rawBytes .slice (b .rawBytes .offsets .At2 (j ))
403408}
404409
405410// RowSuffix returns a []byte of the suffix unique to the row. A row's full key
@@ -415,6 +420,7 @@ func (b *PrefixBytes) RowSuffix(row int) []byte {
415420// accounting for duplicate keys. It takes the index of the row, and the value
416421// of rowSuffixIndex(row).
417422func (b * PrefixBytes ) rowSuffixOffsets (row , i int ) (low uint32 , high uint32 ) {
423+ invariants .CheckBounds (i , b .rawBytes .slices )
418424 // Retrieve the low and high offsets indicating the start and end of the
419425 // row's suffix slice.
420426 low , high = b .rawBytes .offsets .At2 (i )
@@ -493,6 +499,7 @@ func (b *PrefixBytes) Search(k []byte) (rowIndex int, isEqual bool) {
493499 // offset(j) offset(j+1) offset(j+2)
494500 //
495501 j := b .offsetIndexByBundleIndex (h )
502+ invariants .CheckBounds (j + 1 , b .rawBytes .slices )
496503 bundleFirstKey := b .rawBytes .slice (b .rawBytes .offsets .At (j ), b .rawBytes .offsets .At (j + 2 ))
497504 c = bytes .Compare (k , bundleFirstKey )
498505 switch {
@@ -516,7 +523,8 @@ func (b *PrefixBytes) Search(k []byte) (rowIndex int, isEqual bool) {
516523 // among them, but if the seek key doesn't share the previous bundle's
517524 // prefix there's no need.
518525 j := b .offsetIndexByBundleIndex (bi - 1 )
519- bundlePrefix := b .rawBytes .slice (b .rawBytes .offsets .At (j ), b .rawBytes .offsets .At (j + 1 ))
526+ invariants .CheckBounds (j , b .rawBytes .slices )
527+ bundlePrefix := b .rawBytes .slice (b .rawBytes .offsets .At2 (j ))
520528
521529 // The row we are looking for might still be in the previous bundle even
522530 // though the seek key is greater than the first key. This is possible only
@@ -553,6 +561,7 @@ func (b *PrefixBytes) Search(k []byte) (rowIndex int, isEqual bool) {
553561 // The beginning of the zero-indexed i-th key of the bundle is at
554562 // offset(j+i+1).
555563 //
564+ invariants .CheckBounds (j + h + 1 , b .rawBytes .slices )
556565 hStart , hEnd := b .rawBytes .offsets .At2 (j + h + 1 )
557566 // There's a complication with duplicate keys. When keys are repeated,
558567 // the PrefixBytes encoding avoids re-encoding the duplicate key,
0 commit comments