In my opinion code such as this is incorrect:
|
for iter.Seek(prefix); iter.ValidForPrefix(prefix); iter.Next() { |
|
it := iter.Item() |
|
|
|
k := it.Key() |
|
if err := txn.Delete(k); err != nil { |
|
return fmt.Errorf("DeleteAuthor: failed to drop record %x: %w", k, err) |
|
} |
|
} |
Reasoning:
https://pkg.go.dev/github.com/dgraph-io/badger/v3#Item.Key:
Key is only valid as long as item is valid, or transaction is valid. If you need to use it outside its validity, please use KeyCopy.
https://pkg.go.dev/github.com/dgraph-io/badger/v3#Iterator.Item:
Item returns pointer to the current key-value pair. This item is only valid until it.Next() gets called.
In my opinion in this situation the item is only valid until the next iteration therefore key is illegaly reused. KeyCopy should be used instead. It is possible that txn.Delete(...) will remove other data. I imagine this is the case in other places in the code as well.
In my opinion code such as this is incorrect:
go-ssb/graph/builder.go
Lines 105 to 112 in 2cdd828
Reasoning:
https://pkg.go.dev/github.com/dgraph-io/badger/v3#Item.Key:
https://pkg.go.dev/github.com/dgraph-io/badger/v3#Iterator.Item:
In my opinion in this situation the item is only valid until the next iteration therefore key is illegaly reused.
KeyCopyshould be used instead. It is possible thattxn.Delete(...)will remove other data. I imagine this is the case in other places in the code as well.