Skip to content

Commit c9ec067

Browse files
committed
MP3 detection: Detect AAC files by some known magic bytes, otherwise the audio backend might crash if it tried to play the format.
1 parent e936c88 commit c9ec067

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/audio_decoder.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,12 @@ class WMAUnsupportedFormatDecoder : public AudioDecoder {
5050
int FillBuffer(uint8_t*, int) override { return -1; };
5151
};
5252
const char wma_magic[] = { (char)0x30, (char)0x26, (char)0xB2, (char)0x75 };
53+
const std::array<char[2], 4> aac_magics = { {
54+
{ (char)0xFF, (char)0xF1 },
55+
{ (char)0xFF, (char)0xF0 },
56+
{ (char)0xFF, (char)0xF8 },
57+
{ (char)0xFF, (char)0xF9 }
58+
}};
5359

5460
std::unique_ptr<AudioDecoderBase> AudioDecoder::Create(Filesystem_Stream::InputStream& stream, bool resample) {
5561
char magic[4] = { 0 };
@@ -141,6 +147,13 @@ std::unique_ptr<AudioDecoderBase> AudioDecoder::Create(Filesystem_Stream::InputS
141147
return mp3dec;
142148
}
143149

150+
bool is_aac = std::any_of(aac_magics.begin(), aac_magics.end(), [&](auto& mpeg4_magic) {
151+
return memcmp(magic, mpeg4_magic, 2);
152+
});
153+
if (is_aac) {
154+
return nullptr;
155+
}
156+
144157
// Parsing MP3s seems to be the only reliable way to detect them
145158
if (Mpg123Decoder::IsMp3(stream)) {
146159
stream.clear();

0 commit comments

Comments
 (0)