ipfs / ipfs/boxo

datastore/dshelp: Using base32 for datastore key is partially broken

Open
#374 0 comments 0 reactions 0 assignees View on GitHub
need/analysis P2
Dominant language
Go
Stars
316
Forks
163
Avg merge
4d 12h
Merged PRs (30d)
8

Description

I'm not an expert of base32, but as far as I can tell some valid `go-datastore` keys are not valid encoded base32. This happens for example with the `/foo` key, notably used in the standard tests in go-datastore (and a valid key as far as I can tell): https://github.com/ipfs/go-datastore/blob/master/test/basic_tests.go#L40

I reproduced this behavior with `multiformats/go-base32` but also a few online base32 decoder.

Here is some results to illustrate the problem:
```
dshelp.BinaryFromDsKey(ds.NewKey("MY")) --> [102]
dshelp.BinaryFromDsKey(ds.NewKey("FO")) --> [43]
dshelp.BinaryFromDsKey(ds.NewKey("fo")) --> [43]
dshelp.BinaryFromDsKey(ds.NewKey("FOO")) --> [] // <-- oof
dshelp.BinaryFromDsKey(ds.NewKey("foo")) --> [] // <-- oof
dshelp.BinaryFromDsKey(ds.NewKey("FOOO")) --> [43 156]
dshelp.BinaryFromDsKey(ds.NewKey("fooo")) --> [43 156]
```

Additionally, calling `dshelp.BinaryFromDsKey(ds.NewKey("foo"))` **doesn't** return an error.

At this point, I get that changing the encoding is not an option, but I would suggest at least:
- returning an error when that function fail to return a proper result
- adjusting `go-datastore`'s test suite to avoid those problematic keys

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.