Skip to content

Commit

Permalink
fix(sort): Only filter out nodes with positive offsets. (#8077)
Browse files Browse the repository at this point in the history
Negative offsets (e.g., offset: -4) can cause panics when sorting. This can happen when the query has the following characteristics:

1. The query is sorting on an indexed predicate
2. The results include nodes that also don't have the sorted predicate
3. A negative offset is used.

    (panic trace is from v20.11.2-rc1-23-gaf5030a5)
    panic: runtime error: slice bounds out of range [-4:]
    goroutine 1762633 [running]:
    github.com/dgraph-io/dgraph/worker.sortWithIndex(0x1fb12e0, 0xc00906a880, 0xc009068660, 0x0)
            /ext-go/1/src/github.com/dgraph-io/dgraph/worker/sort.go:330 +0x244d
    github.com/dgraph-io/dgraph/worker.processSort.func2(0x1fb12e0, 0xc00906a880, 0xc009068660, 0xc0090686c0)
            /ext-go/1/src/github.com/dgraph-io/dgraph/worker/sort.go:515 +0x3f
    created by github.com/dgraph-io/dgraph/worker.processSort
            /ext-go/1/src/github.com/dgraph-io/dgraph/worker/sort.go:514 +0x52a
  • Loading branch information
danielmai authored Oct 18, 2021
1 parent 3f514fe commit 74d833c
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion worker/sort.go
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,9 @@ BUCKETS:

// Apply the offset on null nodes, if the nodes with value were not enough.
if out[i].offset < len(nullNodes) {
nullNodes = nullNodes[out[i].offset:]
if out[i].offset >= 0 {
nullNodes = nullNodes[out[i].offset:]
}
} else {
nullNodes = nullNodes[:0]
}
Expand Down

0 comments on commit 74d833c

Please sign in to comment.