allegro / allegro/bigcache

queue: Push() panics in v3.0.0

Offen
#263 1 Kommentar 1 Reaktion 0 zugewiesene Personen Auf GitHub ansehen
bug
Vorherrschende Sprache
Go
Sterne
8.2k
Forks
614
Ø Merge
5 T. 12 Std.
Gemergte PRs (30 T.)
1

Beschreibung

**What is the issue you are having?**

```
panic: runtime error: slice bounds out of range [1:0]

goroutine 1 [running]:
github.com/allegro/bigcache/v3/queue.(*BytesQueue).copy(...)
/Users/prashanthpai/go/pkg/mod/github.com/allegro/bigcache/v3@v3.0.0/queue/bytes_queue.go:157
github.com/allegro/bigcache/v3/queue.(*BytesQueue).push(0xc00010ef08, 0xc00010eefd, 0xb, 0xb, 0xb)
/Users/prashanthpai/go/pkg/mod/github.com/allegro/bigcache/v3@v3.0.0/queue/bytes_queue.go:142 +0x1a8
github.com/allegro/bigcache/v3/queue.(*BytesQueue).Push(0xc00010ef08, 0xc00010eefd, 0xb, 0xb, 0xc000100050, 0xc00010ef18, 0x1040f4a)
/Users/prashanthpai/go/pkg/mod/github.com/allegro/bigcache/v3@v3.0.0/queue/bytes_queue.go:100 +0xb2
main.main()
/Users/prashanthpai/bigcache-bug/main.go:7 +0x11c
```

**What is BigCache doing that it shouldn't?**

It's panicking. I haven't looked deeper but the the most likely cause is the integer underflow (`uint64`) here which is hit when `capacity` passed to `NewBytesQueue` is `0`:
https://github.com/allegro/bigcache/blob/55d48f4e069fd81755c7be002903253d961abe44/queue/bytes_queue.go#L251

**This is a regression from `2.2.5`** caused by https://github.com/allegro/bigcache/pull/236

**Minimal, Complete, and Verifiable Example**

```go
package main

import "github.com/allegro/bigcache/v3/queue"

func main() {
q := queue.NewBytesQueue(0, 1024, true)
q.Push([]byte("hello world"))
}
```

**Environment:**

[bigcache v3.0.0](https://github.com/allegro/bigcache/releases/tag/v3.0.0)

```
$ go version
go version go1.15.2 darwin/amd64
```

Beitragsleitfaden

Für dieses Repository ist kein Beitragsleitfaden indexiert

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.