From bb9d22cc2a00aa18e87abea3082ae278f7fc4fb4 Mon Sep 17 00:00:00 2001 From: John Schember Date: Tue, 3 Nov 2026 15:24:24 -0500 Subject: [PATCH] audio: reject headers with bitrate index 0 --- audio.go | 2 +- audio_test.go | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/audio.go b/audio.go index b2156d3..1375ea2 100644 --- a/audio.go +++ b/audio.go @@ -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 } diff --git a/audio_test.go b/audio_test.go index 13c6bec..818316d 100644 --- a/audio_test.go +++ b/audio_test.go @@ -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") + } +}