Iterator readEntry crashes
- Dominant language
- Go
- Stars
- 8.2k
- Forks
- 614
- Avg merge
- 5d 12h
- Merged PRs (30d)
- 1
Description
**What is the issue you are having?**
Sometimes when using EntryInfoIterator to read all entries from the cache, the readEntry() call crashes with the following stack trace:
```
runtime error: makeslice: len out of range
panic(0x1fabc00, 0x27ff350)
/usr/local/go/src/runtime/panic.go:975 +0x3e3
github.com/allegro/bigcache.readEntry(...)
/usr/local/Code/src/github.com/allegro/bigcache/encoding.go:36
github.com/allegro/bigcache.(*EntryInfoIterator).Value(0xc10fd94a50, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0)
/usr/local/Code/src/github.com/allegro/bigcache/iterator.go:120 +0x305
```
We only recently updated from an old version of bigcache. This error seems to indicate the object being read is somehow larger than the maximum slice length, which should not be possible given we marshal the structs to bytes using `protobuf`'s `Marshal()` method:
```
func (m *CacheEntry) Marshal() (dAtA []byte, err error) {
size := m.Size()
dAtA = make([]byte, size)
n, err := m.MarshalTo(dAtA)
if err != nil {
return nil, err
}
return dAtA[:n], nil
}
```
We are running on a 64bit system and we limit the size of all entries to ~1MB anyhow.
**What is BigCache doing that it shouldn't?**
It is not clear reading the code, but it seems related to how readEntry() determines length, perhaps some kind of overflow issue.
**Environment:**
- Version (git sha or release): v2.2.1
- OS (e.g. from `/etc/os-release` or winver.exe): ubuntu 16.04
- go version: 1.14.2
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.