From: Tsuda Kageyu Date: Sun, 24 May 2015 17:41:27 +0000 (+0900) Subject: Fix MPEG::File::firstFrameOffset() and lastFrameOffset(). (#190) X-Git-Tag: v1.10beta~71^2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=618a939c56a815d5098d0b01c02e8c4d430af1b4;p=taglib Fix MPEG::File::firstFrameOffset() and lastFrameOffset(). (#190) --- diff --git a/taglib/mpeg/mpegfile.cpp b/taglib/mpeg/mpegfile.cpp index 0ac87d10..637dfa9b 100644 --- a/taglib/mpeg/mpegfile.cpp +++ b/taglib/mpeg/mpegfile.cpp @@ -433,7 +433,7 @@ long MPEG::File::firstFrameOffset() { long position = 0; - if(ID3v2Tag()) { + if(hasID3v2Tag()) { position = d->ID3v2Location + ID3v2Tag()->header()->completeTagSize(); // Skip duplicate ID3v2 tags. @@ -456,7 +456,7 @@ long MPEG::File::firstFrameOffset() long MPEG::File::lastFrameOffset() { - return previousFrameOffset(ID3v1Tag() ? d->ID3v1Location - 1 : length()); + return previousFrameOffset(hasID3v1Tag() ? d->ID3v1Location - 1 : length()); } bool MPEG::File::hasID3v1Tag() const diff --git a/tests/data/ape-id3v1.mp3 b/tests/data/ape-id3v1.mp3 new file mode 100644 index 00000000..a761d6ca Binary files /dev/null and b/tests/data/ape-id3v1.mp3 differ diff --git a/tests/data/ape-id3v2.mp3 b/tests/data/ape-id3v2.mp3 new file mode 100644 index 00000000..72c1291d Binary files /dev/null and b/tests/data/ape-id3v2.mp3 differ diff --git a/tests/data/ape.mp3 b/tests/data/ape.mp3 new file mode 100644 index 00000000..a17e2699 Binary files /dev/null and b/tests/data/ape.mp3 differ diff --git a/tests/test_mpeg.cpp b/tests/test_mpeg.cpp index 74440b93..d0065365 100644 --- a/tests/test_mpeg.cpp +++ b/tests/test_mpeg.cpp @@ -18,6 +18,7 @@ class TestMPEG : public CppUnit::TestFixture CPPUNIT_TEST(testSaveID3v23); CPPUNIT_TEST(testDuplicateID3v2); CPPUNIT_TEST(testFuzzedFile); + CPPUNIT_TEST(testFrameOffset); CPPUNIT_TEST_SUITE_END(); public: @@ -111,6 +112,28 @@ public: CPPUNIT_ASSERT(f.isValid()); } + void testFrameOffset() + { + { + MPEG::File f(TEST_FILE_PATH_C("ape.mp3")); + CPPUNIT_ASSERT(f.isValid()); + CPPUNIT_ASSERT_EQUAL((long)0x0000, f.firstFrameOffset()); + CPPUNIT_ASSERT_EQUAL((long)0x1FD6, f.lastFrameOffset()); + } + { + MPEG::File f(TEST_FILE_PATH_C("ape-id3v1.mp3")); + CPPUNIT_ASSERT(f.isValid()); + CPPUNIT_ASSERT_EQUAL((long)0x0000, f.firstFrameOffset()); + CPPUNIT_ASSERT_EQUAL((long)0x1FD6, f.lastFrameOffset()); + } + { + MPEG::File f(TEST_FILE_PATH_C("ape-id3v2.mp3")); + CPPUNIT_ASSERT(f.isValid()); + CPPUNIT_ASSERT_EQUAL((long)0x041A, f.firstFrameOffset()); + CPPUNIT_ASSERT_EQUAL((long)0x23F0, f.lastFrameOffset()); + } + } + }; CPPUNIT_TEST_SUITE_REGISTRATION(TestMPEG);