Skip to content

Commit a7cf7d9

Browse files
committed
Bug Fix:
Copy over vs.value into item.vptr, otherwise, when item gets reused it ends up overwriting a value pointer and cause panics. This is the bug which ventured into v1.0.6 of Dgraph, and caused hard to locate panics.
1 parent a6f0866 commit a7cf7d9

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

db.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ func replayFunction(out *DB) func(Entry, valuePointer) error {
100100
first := true
101101
return func(e Entry, vp valuePointer) error { // Function for replaying.
102102
if first {
103-
out.elog.Printf("First key=%s\n", e.Key)
103+
out.elog.Printf("First key=%q\n", e.Key)
104104
}
105105
first = false
106106

iterator.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,9 +182,13 @@ func (item *Item) yieldItemValue() ([]byte, func(), error) {
182182
if vs.Version != item.Version() {
183183
return nil, nil, nil
184184
}
185-
item.vptr = vs.Value
185+
// Bug fix: Always copy the vs.Value into vptr here. Otherwise, when item is reused this
186+
// slice gets overwritten.
187+
item.vptr = y.SafeCopy(item.vptr, vs.Value)
186188
item.meta &^= bitValuePointer // Clear the value pointer bit.
187-
item.meta |= vs.Meta // This meta would only be about value pointer.
189+
if vs.Meta&bitValuePointer > 0 {
190+
item.meta |= bitValuePointer // This meta would only be about value pointer.
191+
}
188192
}
189193
}
190194

0 commit comments

Comments
 (0)