mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +01:00
audio/vorbis: Bug fix: fail to decode too short ogg
This commit is contained in:
parent
86691c67e9
commit
83f168a010
BIN
audio/vorbis/test_tooshort.ogg
Executable file
BIN
audio/vorbis/test_tooshort.ogg
Executable file
Binary file not shown.
@ -172,7 +172,7 @@ func decode(in audio.ReadSeekCloser) (*decoded, int, int, error) {
|
||||
decoder: r,
|
||||
}
|
||||
runtime.SetFinalizer(d, (*decoded).Close)
|
||||
if _, err := d.Read(make([]uint8, 65536)); err != nil {
|
||||
if _, err := d.Read(make([]uint8, 65536)); err != nil && err != io.EOF {
|
||||
return nil, 0, 0, err
|
||||
}
|
||||
if _, err := d.Seek(0, io.SeekStart); err != nil {
|
||||
|
@ -24,18 +24,23 @@ import (
|
||||
. "github.com/hajimehoshi/ebiten/audio/vorbis"
|
||||
)
|
||||
|
||||
var audioContext *audio.Context
|
||||
|
||||
func init() {
|
||||
var err error
|
||||
audioContext, err = audio.NewContext(44100)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestMono(t *testing.T) {
|
||||
bs, err := ioutil.ReadFile("test_mono.ogg")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
c, err := audio.NewContext(44100)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
s, err := Decode(c, audio.BytesReadSeekCloser(bs))
|
||||
s, err := Decode(audioContext, audio.BytesReadSeekCloser(bs))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@ -57,3 +62,21 @@ func TestMono(t *testing.T) {
|
||||
t.Errorf("s.Length(): got: %d, want: %d", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestTooShort(t *testing.T) {
|
||||
bs, err := ioutil.ReadFile("test_tooshort.ogg")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
s, err := Decode(audioContext, audio.BytesReadSeekCloser(bs))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
got := s.Length()
|
||||
want := int64(79424)
|
||||
if got != want {
|
||||
t.Errorf("s.Length(): got: %d, want: %d", got, want)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user