Skip to content

Commit 49510e7

Browse files
authored
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.
1 parent 7f2f2dd commit 49510e7

3 files changed

Lines changed: 7 additions & 2 deletions

File tree

taglib/fileref.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,8 +246,7 @@ namespace
246246
{
247247
File *file = nullptr;
248248

249-
if(MPEG::File::isSupported(stream))
250-
file = new MPEG::File(stream, readAudioProperties, audioPropertiesStyle);
249+
if(false);
251250
#ifdef TAGLIB_WITH_VORBIS
252251
else if(Ogg::Vorbis::File::isSupported(stream))
253252
file = new Ogg::Vorbis::File(stream, readAudioProperties, audioPropertiesStyle);
@@ -300,6 +299,8 @@ namespace
300299
else if(Matroska::File::isSupported(stream))
301300
file = new Matroska::File(stream, readAudioProperties, audioPropertiesStyle);
302301
#endif
302+
else if(MPEG::File::isSupported(stream))
303+
file = new MPEG::File(stream, readAudioProperties, audioPropertiesStyle);
303304

304305
// isSupported() only does a quick check, so double check the file here.
305306

tests/data/mpeg-sync-flac.flac

834 Bytes
Binary file not shown.

tests/test_fileref_detect.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ class TestFileRefDetectByContent : public CppUnit::TestFixture
167167
CPPUNIT_TEST(testSilence44SFlac);
168168
CPPUNIT_TEST(testSinewaveFlac);
169169
CPPUNIT_TEST(testZeroSizedPaddingFlac);
170+
CPPUNIT_TEST(testFLACWithMPEGSyncBytes);
170171
// Ogg::Speex::File
171172
CPPUNIT_TEST(testEmptySpx);
172173
// Ogg::Opus::File
@@ -326,6 +327,9 @@ class TestFileRefDetectByContent : public CppUnit::TestFixture
326327
void testZeroSizedPaddingFlac() {
327328
detectByContent<FLAC::File>("zero-sized-padding.flac");
328329
}
330+
void testFLACWithMPEGSyncBytes() {
331+
detectByContent<FLAC::File>("mpeg-sync-flac.flac");
332+
}
329333

330334
// -- Ogg::Speex::File --
331335
void testEmptySpx() { detectByContent<Ogg::Speex::File>("empty.spx"); }

0 commit comments

Comments
 (0)