From 973b001a259c71a5882d3cac3c78bdf06bd2a86c Mon Sep 17 00:00:00 2001 From: Uwe Klotz Date: Sun, 24 Jan 2021 20:17:02 +0100 Subject: Prevent invalid cover art hash values --- src/library/coverart.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/library/coverart.cpp b/src/library/coverart.cpp index db06332155..dcaf17a9da 100644 --- a/src/library/coverart.cpp +++ b/src/library/coverart.cpp @@ -51,14 +51,22 @@ QString coverInfoToString(const CoverInfo& info) { //static quint16 CoverImageUtils::calculateHash( const QImage& image) { - const auto hash = qChecksum( + auto hash = qChecksum( reinterpret_cast(image.constBits()), #if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0) image.sizeInBytes() #else image.byteCount() #endif - ); + ); + // In rare cases the calculated checksum could be equal to the + // reserved value defaultHash() which might cause unexpected + // behavior. In this case we simply invert all bits to get a hash + // value that is considered valid. + // https://mixxx.discourse.group/t/mixxx-2-2-4-reads-id3v1-tags-mixxx-2-3-or-2-4-does-not/21041/11 + if (hash == defaultHash() && !image.isNull()) { + hash = ~hash; + } DEBUG_ASSERT(image.isNull() || isValidHash(hash)); DEBUG_ASSERT(!image.isNull() || hash == defaultHash()); return hash; -- cgit v1.2.3