Skip to content

Commit

Permalink
Add nil pointer checks for postings before dereference (#271)
Browse files Browse the repository at this point in the history
  • Loading branch information
abhinavdangeti authored Oct 16, 2024
1 parent 9a80f5f commit bf971e6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
4 changes: 4 additions & 0 deletions merge.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,10 @@ func writePostings(postings *roaring.Bitmap, tfEncoder, locEncoder *chunkedIntCo
use1HitEncoding func(uint64) (bool, uint64, uint64),
w *CountHashWriter, bufMaxVarintLen64 []byte) (
offset uint64, err error) {
if postings == nil {
return 0, nil
}

termCardinality := postings.GetCardinality()
if termCardinality <= 0 {
return 0, nil
Expand Down
7 changes: 5 additions & 2 deletions section_inverted_text_index.go
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,6 @@ func (i *invertedIndexOpaque) BytesRead() uint64 {
func (i *invertedIndexOpaque) ResetBytesRead(uint64) {}

func (io *invertedIndexOpaque) writeDicts(w *CountHashWriter) (dictOffsets []uint64, err error) {

if io.results == nil || len(io.results) == 0 {
return nil, nil
}
Expand Down Expand Up @@ -462,7 +461,11 @@ func (io *invertedIndexOpaque) writeDicts(w *CountHashWriter) (dictOffsets []uin
locs := io.Locs[pid]
locOffset := 0

chunkSize, err := getChunkSize(io.chunkMode, postingsBS.GetCardinality(), uint64(len(io.results)))
var cardinality uint64
if postingsBS != nil {
cardinality = postingsBS.GetCardinality()
}
chunkSize, err := getChunkSize(io.chunkMode, cardinality, uint64(len(io.results)))
if err != nil {
return nil, err
}
Expand Down

0 comments on commit bf971e6

Please sign in to comment.