8000 Illegal slice reuse in Badger code · Issue #331 · ssbc/go-ssb · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
Illegal slice reuse in Badger code #331
Open
@boreq

Description

@boreq

In my opinion code such as this is incorrect:

go-ssb/graph/builder.go

Lines 105 to 112 in 2cdd828

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0