From 49510e7d5a4b341a92ff962d0808bea3d5a0bfc8 Mon Sep 17 00:00:00 2001 From: Daniel <790119+DanTheMan827@users.noreply.github.com> Date: Sat, 4 Apr 2026 01:01:41 -0500 Subject: [PATCH] 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. --- taglib/fileref.cpp | 5 +++-- tests/data/mpeg-sync-flac.flac | Bin 0 -> 834 bytes tests/test_fileref_detect.cpp | 4 ++++ 3 files changed, 7 insertions(+), 2 deletions(-) create mode 100644 tests/data/mpeg-sync-flac.flac diff --git a/taglib/fileref.cpp b/taglib/fileref.cpp index a8c3404f..e0284c6a 100644 --- a/taglib/fileref.cpp +++ b/taglib/fileref.cpp @@ -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. diff --git a/tests/data/mpeg-sync-flac.flac b/tests/data/mpeg-sync-flac.flac new file mode 100644 index 0000000000000000000000000000000000000000..6b92aae902e9c752a078285f59d343ff50553cf1 GIT binary patch literal 834 zcmY+>T}YF06bA7Bw3c7Fx4GtXL|Vy6Qq0YGo<1 zKnVmbC`1H{!D845T8WG$c@aciNJ2<-p`s&}D02_bl@A9FzlU>ox-Yn!g%CzbNU4>Z znyk-F8zQ|&-1e;mUv;}X&t8lcMxL!s^a-I(o$QMwl8LA+A}m8|kYb)HABWPuP+A3) z9;1Bsp##fQS2c9-2esJi+y+zF}Ksl?_ zt%uOz6)L&~<^G{IdLY$0<<&t_fcp9vIufL=??UP@<@Q2(@2P)kNHa^RUC_~KYQPL> zUr^yNls`q;qLBQAiq}KOhAB@gRM1b|_y!fGo`NjCgmhz6$uCInr#_5AMbD{6D(Ltm zB|U&n7^$m9$Y7#AUW1HwDzOL^+o*dX=wt)+^gm>(qjW=%*+H4KkfoLicpz&5b=MD- z=&9}BP^pIc)C<}2sLR=qT}iz?2bC!(%NgiY237PLDpyg1OOWFdWoUsau2AnPpwn&C f$P83@laiOAs#a=e5~_Amcm5_5PPyhh literal 0 HcmV?d00001 diff --git a/tests/test_fileref_detect.cpp b/tests/test_fileref_detect.cpp index 837c82fb..a5e74804 100644 --- a/tests/test_fileref_detect.cpp +++ b/tests/test_fileref_detect.cpp @@ -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("zero-sized-padding.flac"); } + void testFLACWithMPEGSyncBytes() { + detectByContent("mpeg-sync-flac.flac"); + } // -- Ogg::Speex::File -- void testEmptySpx() { detectByContent("empty.spx"); }