Skip to content

Commit

Permalink
Add Seek testdata & fix out-of-range check
Browse files Browse the repository at this point in the history
Contains one fixed & one still failing test.
  • Loading branch information
MarkKremer committed Aug 8, 2024
1 parent e2b51c0 commit 240665e
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 1 addition & 1 deletion flac.go
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ func (stream *Stream) Seek(sampleNum uint64) (uint64, error) {

rs := stream.r.(io.ReadSeeker)

isBiggerThanStream := stream.Info.NSamples != 0 && sampleNum > stream.Info.NSamples
isBiggerThanStream := stream.Info.NSamples != 0 && sampleNum >= stream.Info.NSamples
if isBiggerThanStream || sampleNum < 0 {
return 0, fmt.Errorf("unable to seek to sample number %d", sampleNum)
}
Expand Down
2 changes: 2 additions & 0 deletions flac_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ func TestSeek(t *testing.T) {
{seek: 100, expected: 0},
{seek: 8192, expected: 8192},
{seek: 8191, expected: 4096},
{seek: 40960 + 2723 - 1, expected: 40960}, // last sample
{seek: 40960 + 2723, expected: 0, err: "unable to seek to sample number 43683"}, // one after last sample
}

stream, err := flac.NewSeek(f)
Expand Down

0 comments on commit 240665e

Please sign in to comment.