Move MPEG check to end of content-based detection (#1319)

MPEG::File::isSupported() scans for frame sync bytes that can appear
in other files, causing them to be misidentified as MP3.

This also includes a test with such a file.
This commit is contained in:
Daniel
2026-04-04 01:01:41 -05:00
committed by GitHub
parent 7f2f2ddcaf
commit 49510e7d5a
3 changed files with 7 additions and 2 deletions

View File

@ -246,8 +246,7 @@ namespace
{
File *file = nullptr;
if(MPEG::File::isSupported(stream))
file = new MPEG::File(stream, readAudioProperties, audioPropertiesStyle);
if(false);
#ifdef TAGLIB_WITH_VORBIS
else if(Ogg::Vorbis::File::isSupported(stream))
file = new Ogg::Vorbis::File(stream, readAudioProperties, audioPropertiesStyle);
@ -300,6 +299,8 @@ namespace
else if(Matroska::File::isSupported(stream))
file = new Matroska::File(stream, readAudioProperties, audioPropertiesStyle);
#endif
else if(MPEG::File::isSupported(stream))
file = new MPEG::File(stream, readAudioProperties, audioPropertiesStyle);
// isSupported() only does a quick check, so double check the file here.

Binary file not shown.

View File

@ -167,6 +167,7 @@ class TestFileRefDetectByContent : public CppUnit::TestFixture
CPPUNIT_TEST(testSilence44SFlac);
CPPUNIT_TEST(testSinewaveFlac);
CPPUNIT_TEST(testZeroSizedPaddingFlac);
CPPUNIT_TEST(testFLACWithMPEGSyncBytes);
// Ogg::Speex::File
CPPUNIT_TEST(testEmptySpx);
// Ogg::Opus::File
@ -326,6 +327,9 @@ public:
void testZeroSizedPaddingFlac() {
detectByContent<FLAC::File>("zero-sized-padding.flac");
}
void testFLACWithMPEGSyncBytes() {
detectByContent<FLAC::File>("mpeg-sync-flac.flac");
}
// -- Ogg::Speex::File --
void testEmptySpx() { detectByContent<Ogg::Speex::File>("empty.spx"); }