diff --git a/audio/loop.go b/audio/loop.go index 22ff2c9ad..38813023b 100644 --- a/audio/loop.go +++ b/audio/loop.go @@ -60,6 +60,9 @@ func (i *InfiniteLoop) Seek(offset int64, whence int) (int64, error) { case io.SeekEnd: return 0, fmt.Errorf("audio: whence must be io.SeekStart or io.SeekCurrent for InfiniteLoop") } + if next < 0 { + return 0, fmt.Errorf("audio: position must >= 0") + } next %= i.size pos, err := i.stream.Seek(next, io.SeekStart) if err != nil { diff --git a/audio/loop_test.go b/audio/loop_test.go index 5cc16da2f..55747b7d2 100644 --- a/audio/loop_test.go +++ b/audio/loop_test.go @@ -72,4 +72,9 @@ func TestInfiniteLoop(t *testing.T) { t.Errorf("index: %d, got: %v, want: %v", i, got, want) } } + + // Seek to negative position is an error. + if _, err := l.Seek(-1, io.SeekStart); err == nil { + t.Errorf("got: %v, want: %v", err, nil) + } }