From 314407f8348907cf00da9c6064f46ed54c4adf1b Mon Sep 17 00:00:00 2001
From: Lawrence Rust <lvr@softsystem.co.uk>
Date: Thu, 12 Jul 2012 17:56:11 +0200
Subject: [PATCH] MythMusic: Filter cached cddb discIDs to prevent incorrect CD identification
In cddb.cpp, Dbase::CacheGet uses the QMap::find function to iterate
over the cached cddb records that match a given discID. The Qt docs
for 4.7 say that incrementing the iterator returns the next QMap value
with the requested key but in testing values with different keys can be
returned.
This patch works around this Qt bug by verifying the key.
Fixes #10892
Signed-off-by: Lawrence Rust <lvr@softsystem.co.uk>
---
mythplugins/mythmusic/mythmusic/cddb.cpp | 21 ++++++++++++++-------
1 files changed, 14 insertions(+), 7 deletions(-)
diff --git a/mythplugins/mythmusic/mythmusic/cddb.cpp b/mythplugins/mythmusic/mythmusic/cddb.cpp
index e08e33d..1876840 100644
a
|
b
|
Cddb::Album::operator QString() const |
483 | 483 | bool Dbase::Search(Cddb::Matches& res, const Cddb::discid_t discID) |
484 | 484 | { |
485 | 485 | res.matches.empty(); |
| 486 | res.discID = discID; |
486 | 487 | |
487 | 488 | if (CacheGet(res, discID)) |
488 | 489 | return true; |
… |
… |
bool Dbase::Write(const Cddb::Album& album) |
572 | 573 | // static |
573 | 574 | void Dbase::MakeAlias(const Cddb::Album& album, const Cddb::discid_t discID) |
574 | 575 | { |
575 | | s_cache[ discID] = album; |
| 576 | LOG(VB_MEDIA, LOG_DEBUG, QString("Cddb MakeAlias %1 for %2 ") |
| 577 | .arg(discID,0,16).arg(album.discID,0,16) |
| 578 | + album.genre + " " + album.artist + " / " + album.title); |
| 579 | s_cache.insert(discID, album)->discID = discID; |
576 | 580 | } |
577 | 581 | |
578 | 582 | // Create a new entry for a discID |
579 | 583 | // static |
580 | 584 | void Dbase::New(const Cddb::discid_t discID, const Cddb::Toc& toc) |
581 | 585 | { |
582 | | (s_cache[ discID] = Cddb::Album(discID)).toc = toc; |
| 586 | s_cache.insert(discID, Cddb::Album(discID))->toc = toc; |
583 | 587 | } |
584 | 588 | |
585 | 589 | // static |
586 | 590 | void Dbase::CachePut(const Cddb::Album& album) |
587 | 591 | { |
588 | | s_cache[ album.discID] = album; |
| 592 | LOG(VB_MEDIA, LOG_DEBUG, QString("Cddb CachePut %1 ") |
| 593 | .arg(album.discID,0,16) |
| 594 | + album.genre + " " + album.artist + " / " + album.title); |
| 595 | s_cache.insertMulti(album.discID, album); |
589 | 596 | } |
590 | 597 | |
591 | 598 | // static |
… |
… |
bool Dbase::CacheGet(Cddb::Matches& res, const Cddb::discid_t discID) |
594 | 601 | bool ret = false; |
595 | 602 | for (cache_t::const_iterator it = s_cache.find(discID); it != s_cache.end(); ++it) |
596 | 603 | { |
597 | | // NB it->discID may not equal discID if it's an alias |
598 | | if (it->discID) |
| 604 | if (it->discID == discID) |
599 | 605 | { |
600 | 606 | ret = true; |
601 | 607 | res.discID = discID; |
602 | | LOG(VB_MEDIA, LOG_DEBUG, QString("Cddb CacheGet found %1 "). |
603 | | arg(discID,0,16) + it->genre + " " + it->artist + " / " + it->title); |
| 608 | LOG(VB_MEDIA, LOG_DEBUG, QString("Cddb CacheGet %1 found %2 ") |
| 609 | .arg(discID,0,16).arg(it->discID,0,16) |
| 610 | + it->genre + " " + it->artist + " / " + it->title); |
604 | 611 | |
605 | 612 | // If it's marker for 'no match' then genre is empty |
606 | 613 | if (!it->genre.isEmpty()) |