From 83f168a010cce1416e06517b5aaf4a4eee338ae0 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Sat, 7 Apr 2018 22:13:12 +0900 Subject: [PATCH] audio/vorbis: Bug fix: fail to decode too short ogg --- audio/vorbis/test_tooshort.ogg | Bin 0 -> 7913 bytes audio/vorbis/vorbis.go | 2 +- audio/vorbis/vorbis_test.go | 35 +++++++++++++++++++++++++++------ 3 files changed, 30 insertions(+), 7 deletions(-) create mode 100755 audio/vorbis/test_tooshort.ogg diff --git a/audio/vorbis/test_tooshort.ogg b/audio/vorbis/test_tooshort.ogg new file mode 100755 index 0000000000000000000000000000000000000000..66387bd549585443c3d515adb4b5e78434e7983a GIT binary patch literal 7913 zcmaiY2|U!@_y1?IGnTAFqsDGT8Adfi_85d=#+E19_v|8yLI_#L#8|Qok+D-KN?Ee6 zgH)0%;h_@J`u_~i^Zh>m@9+2e{ywie_jNz_+(OY@xm{r^2L81@+*1?kov ze(uLi1Kbea9*%@P_6S3Sk|Ih;QAtr5A#3X6>){vR66oR^grxI^Fzs(eYU>an04q3y zGDdVp4X5G(fCm5^B#~Shu7*eou~0TFi)cU}bt)!g5feILPD!Y)zdHolSpWbSfhbwF zl;TB0&q0hEOeQ6u0ON7)R2hOL(flojtz%2t$+xtj)XR4eDaFcZ!vuhK(KHZ?<;T%G z$9SM^r@MBpH1Dfh3AZBGvbcouDDVP_s~RyzB5WNB6a$ZB6L1P}$P37k#iH>~CFtA!7Y zNSc0@H|J9sQP#7tG{J*Uu)S4?%VbFKWJshD*0u)GKNb|@dagm~Tm?DOlxXJ^7Gu$m|Iu7+NG|_(({%5V12jQfcKgG-{U!BqlHCFFEPEF20YIN>;^aF6 z&}ReD-GORgI~%0?f@nPO#hCkVC(zvv0GcRxr$77!XbqggSb&OEp!#H>$s}kBx<&r` z6TOEQP!X{_SCVHGt8(haJ+nlCY+;40I?#Pd;DY$V_XzSZd2;~6MP4W<=g%2?nqZkD z(_EgFv*$tYLE(AOm&o4i&VuY=a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`rymGQls#Q-Ze>kCjnxY|AVO3UJT#o|SIUZ#6?mn^08 zt`M2Ap{mj$9N516AZ${5r zYiwL6#-0^RjvCM+UEq0 z?e3j!?d&K>R0Y=P9MMq^lJ}-B(Pr09SO7UA)mnXK`Apo0J3h`|&^_nc=P+j~A7{9V z-J-tKLEW|R4%Z$$u<@JuRq$B;nb7mEvv0b3)+Q*q`+Gx`9>*(I`-k>>hyQAZ>@1;a zT;0{cE%gWWB@P{Fe;Rz_7v5xOXJV%2r_YJB!EX19JJ!{kcvrqZg#1zCtNgjj)E=-@ zGB4}Zs^A@_)bVmZkUfdl*Y$MyN#$BTP!__}hza@e1rYt^@<{aOQMD;qhF9E*%*#=0 zSUG(gwodTEk@jA<)$nOgR;=H-RxSB$B*WJA67Ov}&o_`I@wFK;X*hqn=*SMqrir9@ zHED;-BY+`WaNy-fAGljc;3=P(v|E?dZ2chSdt5joMQ}`}o8wQv zEy~pVTD0so^*la&3dnc)5qdn->g2VsM&<^TWy literal 0 HcmV?d00001 diff --git a/audio/vorbis/vorbis.go b/audio/vorbis/vorbis.go index 5c2d238b0..4666a8a52 100644 --- a/audio/vorbis/vorbis.go +++ b/audio/vorbis/vorbis.go @@ -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 { diff --git a/audio/vorbis/vorbis_test.go b/audio/vorbis/vorbis_test.go index 5bd64c1f9..d03f25b2a 100644 --- a/audio/vorbis/vorbis_test.go +++ b/audio/vorbis/vorbis_test.go @@ -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) + } +}