mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-26 03:38:55 +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,
|
posInBytes: 0,
|
||||||
decoder: r,
|
decoder: r,
|
||||||
}
|
}
|
||||||
if _, err := d.Read(make([]byte, 65536)); err != nil && err != io.EOF {
|
if _, ok := in.(io.Seeker); ok {
|
||||||
return nil, 0, 0, err
|
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 _, err := d.Seek(0, io.SeekStart); err != nil {
|
||||||
|
return nil, 0, 0, err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return d, r.Channels(), r.SampleRate(), nil
|
return d, r.Channels(), r.SampleRate(), nil
|
||||||
}
|
}
|
||||||
|
@ -16,6 +16,7 @@ package vorbis_test
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"io"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/jfreymuth/oggvorbis"
|
"github.com/jfreymuth/oggvorbis"
|
||||||
@ -66,3 +67,21 @@ func TestTooShort(t *testing.T) {
|
|||||||
t.Errorf("s.Length(): got: %d, want: %d", got, want)
|
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