From e958fa0bfad51522b763a0b7348a4643992d35cc Mon Sep 17 00:00:00 2001 From: abbott3344 Date: Fri, 26 Jun 2026 08:12:16 +0300 Subject: [PATCH] Fix overflow for large Apple Music cnID values (#1373) cnID must be longlong instead of int as Apple Music cnID values can now exceed the range of a 32-bit integer and require 64-bit aka longlong. --------- Co-authored-by: Urs Fleisch --- taglib/mp4/mp4itemfactory.cpp | 4 ++-- tests/test_mp4.cpp | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/taglib/mp4/mp4itemfactory.cpp b/taglib/mp4/mp4itemfactory.cpp index 9e591ad3..dbbfe5c2 100644 --- a/taglib/mp4/mp4itemfactory.cpp +++ b/taglib/mp4/mp4itemfactory.cpp @@ -172,7 +172,7 @@ std::pair ItemFactory::itemFromProperty( case ItemHandlerType::UInt: return {name, Item(static_cast(values.front().toInt()))}; case ItemHandlerType::LongLong: - return {name, Item(static_cast(values.front().toInt()))}; + return {name, Item(values.front().toLongLong())}; case ItemHandlerType::Byte: return {name, Item(static_cast(values.front().toInt()))}; case ItemHandlerType::Bool: @@ -299,7 +299,7 @@ ItemFactory::NameHandlerMap ItemFactory::nameHandlerMap() const {"rate", ItemHandlerType::TextOrInt}, {"tvsn", ItemHandlerType::UInt}, {"tves", ItemHandlerType::UInt}, - {"cnID", ItemHandlerType::UInt}, + {"cnID", ItemHandlerType::LongLong}, {"sfID", ItemHandlerType::UInt}, {"atID", ItemHandlerType::UInt}, {"geID", ItemHandlerType::UInt}, diff --git a/tests/test_mp4.cpp b/tests/test_mp4.cpp index d037a14f..a1f396d8 100644 --- a/tests/test_mp4.cpp +++ b/tests/test_mp4.cpp @@ -883,6 +883,7 @@ public: tag->setItem("trkn", MP4::Item(2, 10)); tag->setItem("rate", MP4::Item(80)); tag->setItem("plID", MP4::Item(1540934238LL)); + tag->setItem("cnID", MP4::Item(9876543210LL)); tag->setItem("rtng", MP4::Item(static_cast(2))); f.save(); } @@ -904,6 +905,7 @@ public: CPPUNIT_ASSERT_EQUAL(10, item.toIntPair().second); CPPUNIT_ASSERT_EQUAL(80, tag->item("rate").toInt()); CPPUNIT_ASSERT_EQUAL(1540934238LL, tag->item("plID").toLongLong()); + CPPUNIT_ASSERT_EQUAL(9876543210LL, tag->item("cnID").toLongLong()); CPPUNIT_ASSERT_EQUAL(static_cast(2), tag->item("rtng").toByte()); PropertyMap properties = tag->properties(); CPPUNIT_ASSERT_EQUAL(StringList("123"), properties.value("TESTINTEGER"));