Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion audio.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ func (a *Audio) decodeHeader() int {
}

bitrateIndex := a.buf.read(4) - 1
if bitrateIndex > 13 {
if bitrateIndex < 0 || bitrateIndex > 13 {
return 0
}

Expand Down
14 changes: 14 additions & 0 deletions audio_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,17 @@ func runSynthWindowParity(t *testing.T, fn synthWindowFunc, tol float32) {
}
}
}

// TestDecodeHeaderFreeFormat checks a header with bitrate index 0 is rejected.
func TestDecodeHeaderFreeFormat(t *testing.T) {
buf, err := NewBuffer(nil)
if err != nil {
t.Fatal(err)
}
// MPEG-1 Layer II, no CRC, bitrate index 0, 44.1 kHz, stereo.
buf.Write([]byte{0xFF, 0xFD, 0x00, 0x00, 0x00, 0x00})

if NewAudio(buf).HasHeader() {
t.Fatal("header with bitrate index 0 accepted")
}
}
Loading