Skip to content

Commit

Permalink
Fix crash when trying to use shortest path with a password predicate. (
Browse files Browse the repository at this point in the history
…#3662)

The crash happens because querying this predicate does not populate the
uid matrix, resulting in an out-of-index error. This fix just checks the
size of the uid matrix before trying to access it.
  • Loading branch information
martinmr authored Jul 12, 2019
1 parent fd0ea1f commit 60b2b15
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
20 changes: 19 additions & 1 deletion query/query3_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,6 @@ func TestTwoShortestPathMinWeight(t *testing.T) {
}

func TestShortestPath(t *testing.T) {

query := `
{
A as shortest(from:0x01, to:31) {
Expand Down Expand Up @@ -517,6 +516,25 @@ func TestShortestPathRev(t *testing.T) {
js)
}

// Regression test for https://github.com/dgraph-io/dgraph/issues/3657.
func TestShortestPathPassword(t *testing.T) {
query := `
{
A as shortest(from:0x01, to:31) {
password
friend
}
me(func: uid( A)) {
name
}
}`
js := processQueryNoErr(t, query)
require.JSONEq(t,
`{"data": {"_path_":[{"uid":"0x1", "_weight_": 1, "friend":{"uid":"0x1f"}}],
"me":[{"name":"Michonne"},{"name":"Andrea"}]}}`, js)
}

func TestFacetVarRetrieval(t *testing.T) {

query := `
Expand Down
6 changes: 6 additions & 0 deletions query/shortest.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,12 @@ func (sg *SubGraph) expandOut(ctx context.Context,

// Send the destuids in res chan.
for mIdx, fromUID := range subgraph.SrcUIDs.Uids {
// This can happen when trying to go traverse a predicate of type password
// for example.
if mIdx >= len(subgraph.uidMatrix) {
continue
}

for lIdx, toUID := range subgraph.uidMatrix[mIdx].Uids {
if adjacencyMap[fromUID] == nil {
adjacencyMap[fromUID] = make(map[uint64]mapItem)
Expand Down

0 comments on commit 60b2b15

Please sign in to comment.