mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-25 11:18:54 +01:00
audio/vorbis: bug fix: error when a non-seeker source is given to Decode*
Closes #2252
This commit is contained in:
parent
f8395e234a
commit
1251bd5792
@ -130,11 +130,13 @@ func decode(in io.Reader) (*decoded, int, int, error) {
|
||||
posInBytes: 0,
|
||||
decoder: r,
|
||||
}
|
||||
if _, err := d.Read(make([]byte, 65536)); err != nil && err != io.EOF {
|
||||
return nil, 0, 0, err
|
||||
}
|
||||
if _, err := d.Seek(0, io.SeekStart); err != nil {
|
||||
return nil, 0, 0, err
|
||||
if _, ok := in.(io.Seeker); ok {
|
||||
if _, err := d.Read(make([]byte, 65536)); err != nil && err != io.EOF {
|
||||
return nil, 0, 0, err
|
||||
}
|
||||
if _, err := d.Seek(0, io.SeekStart); err != nil {
|
||||
return nil, 0, 0, err
|
||||
}
|
||||
}
|
||||
return d, r.Channels(), r.SampleRate(), nil
|
||||
}
|
||||
|
@ -16,6 +16,7 @@ package vorbis_test
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"io"
|
||||
"testing"
|
||||
|
||||
"github.com/jfreymuth/oggvorbis"
|
||||
@ -66,3 +67,21 @@ func TestTooShort(t *testing.T) {
|
||||
t.Errorf("s.Length(): got: %d, want: %d", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
type reader struct {
|
||||
r io.Reader
|
||||
}
|
||||
|
||||
func (r *reader) Read(buf []byte) (int, error) {
|
||||
return r.r.Read(buf)
|
||||
}
|
||||
|
||||
func TestNonSeeker(t *testing.T) {
|
||||
bs := test_tooshort_ogg
|
||||
|
||||
s, err := vorbis.DecodeWithSampleRate(audioContext.SampleRate(), &reader{r: bytes.NewReader(bs)})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
_ = s
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user