From 76ebcd41f51da6361dbb96a782e14c07149f4587 Mon Sep 17 00:00:00 2001 From: Marcos CARDINOT Date: Wed, 16 Jul 2014 12:01:11 +0100 Subject: [PATCH] SoundSource - Fixing TString convertion - Try converting a TString from a metadata directly to QString can produce segfaults. - We must check if it is valid before convert it. --- src/soundsource.cpp | 90 ++++++++++++++++++++++++--------------------- src/soundsource.h | 4 +- 2 files changed, 52 insertions(+), 42 deletions(-) diff --git a/src/soundsource.cpp b/src/soundsource.cpp index 32ac5dcd311..c447a03d090 100644 --- a/src/soundsource.cpp +++ b/src/soundsource.cpp @@ -232,6 +232,13 @@ void SoundSource::setKey(QString key){ m_sKey = key; } +QString SoundSource::getQString(TagLib::String TString) { + if (TString != TagLib::String::null) { + return TStringToQString(TString); + } + return QString(); +} + bool SoundSource::processTaglibFile(TagLib::File& f) { if (s_bDebugMetadata) qDebug() << "Parsing" << getFilename(); @@ -239,19 +246,20 @@ bool SoundSource::processTaglibFile(TagLib::File& f) { if (f.isValid()) { TagLib::Tag *tag = f.tag(); if (tag) { - QString title = TStringToQString(tag->title()); + + QString title = getQString(tag->title()); setTitle(title); - QString artist = TStringToQString(tag->artist()); + QString artist = getQString(tag->artist()); setArtist(artist); - QString album = TStringToQString(tag->album()); + QString album = getQString(tag->album()); setAlbum(album); - QString comment = TStringToQString(tag->comment()); + QString comment = getQString(tag->comment()); setComment(comment); - QString genre = TStringToQString(tag->genre()); + QString genre = getQString(tag->genre()); setGenre(genre); int iYear = tag->year(); @@ -322,19 +330,19 @@ bool SoundSource::processID3v2Tag(TagLib::ID3v2::Tag* id3v2) { TagLib::ID3v2::FrameList::ConstIterator it = id3v2->frameList().begin(); for(; it != id3v2->frameList().end(); it++) { qDebug() << "ID3V2" << (*it)->frameID().data() << "-" - << TStringToQString((*it)->toString()); + << getQString((*it)->toString()); } } TagLib::ID3v2::FrameList bpmFrame = id3v2->frameListMap()["TBPM"]; if (!bpmFrame.isEmpty()) { - QString sBpm = TStringToQString(bpmFrame.front()->toString()); + QString sBpm = getQString(bpmFrame.front()->toString()); processBpmString("ID3v2", sBpm); } TagLib::ID3v2::FrameList keyFrame = id3v2->frameListMap()["TKEY"]; if (!keyFrame.isEmpty()) { - QString sKey = TStringToQString(keyFrame.front()->toString()); + QString sKey = getQString(keyFrame.front()->toString()); setKey(sKey); } // Foobar2000-style ID3v2.3.0 tags @@ -345,13 +353,13 @@ bool SoundSource::processID3v2Tag(TagLib::ID3v2::Tag* id3v2) { dynamic_cast( *it ); if ( ReplayGainframe && ReplayGainframe->fieldList().size() >= 2 ) { - QString desc = TStringToQString( ReplayGainframe->description() ).toLower(); + QString desc = getQString( ReplayGainframe->description() ).toLower(); if ( desc == "replaygain_album_gain" ){ - QString sReplayGain = TStringToQString( ReplayGainframe->fieldList()[1]); + QString sReplayGain = getQString( ReplayGainframe->fieldList()[1]); parseReplayGainString(sReplayGain); } if ( desc == "replaygain_track_gain" ){ - QString sReplayGain = TStringToQString( ReplayGainframe->fieldList()[1]); + QString sReplayGain = getQString( ReplayGainframe->fieldList()[1]); parseReplayGainString(sReplayGain); } } @@ -359,17 +367,17 @@ bool SoundSource::processID3v2Tag(TagLib::ID3v2::Tag* id3v2) { TagLib::ID3v2::FrameList albumArtistFrame = id3v2->frameListMap()["TPE2"]; if (!albumArtistFrame.isEmpty()) { - QString sAlbumArtist = TStringToQString(albumArtistFrame.front()->toString()); + QString sAlbumArtist = getQString(albumArtistFrame.front()->toString()); setAlbumArtist(sAlbumArtist); } TagLib::ID3v2::FrameList composerFrame = id3v2->frameListMap()["TCOM"]; if (!composerFrame.isEmpty()) { - QString sComposer = TStringToQString(composerFrame.front()->toString()); + QString sComposer = getQString(composerFrame.front()->toString()); setComposer(sComposer); } TagLib::ID3v2::FrameList groupingFrame = id3v2->frameListMap()["TIT1"]; if (!groupingFrame.isEmpty()) { - QString sGrouping = TStringToQString(groupingFrame.front()->toString()); + QString sGrouping = getQString(groupingFrame.front()->toString()); setGrouping(sGrouping); } @@ -392,7 +400,7 @@ bool SoundSource::processAPETag(TagLib::APE::Tag* ape) { if (s_bDebugMetadata) { for(TagLib::APE::ItemListMap::ConstIterator it = ape->itemListMap().begin(); it != ape->itemListMap().end(); ++it) { - qDebug() << "APE" << TStringToQString((*it).first) << "-" << TStringToQString((*it).second.toString()); + qDebug() << "APE" << getQString((*it).first) << "-" << getQString((*it).second.toString()); } } @@ -412,31 +420,31 @@ bool SoundSource::processAPETag(TagLib::APE::Tag* ape) { } if (ape->itemListMap().contains("BPM")) { - QString sBpm = TStringToQString(ape->itemListMap()["BPM"].toString()); + QString sBpm = getQString(ape->itemListMap()["BPM"].toString()); processBpmString("APE", sBpm); } if (ape->itemListMap().contains("REPLAYGAIN_ALBUM_GAIN")) { - QString sReplayGain = TStringToQString(ape->itemListMap()["REPLAYGAIN_ALBUM_GAIN"].toString()); + QString sReplayGain = getQString(ape->itemListMap()["REPLAYGAIN_ALBUM_GAIN"].toString()); parseReplayGainString(sReplayGain); } //Prefer track gain over album gain. if (ape->itemListMap().contains("REPLAYGAIN_TRACK_GAIN")) { - QString sReplayGain = TStringToQString(ape->itemListMap()["REPLAYGAIN_TRACK_GAIN"].toString()); + QString sReplayGain = getQString(ape->itemListMap()["REPLAYGAIN_TRACK_GAIN"].toString()); parseReplayGainString(sReplayGain); } if (ape->itemListMap().contains("Album Artist")) { - m_sAlbumArtist = TStringToQString(ape->itemListMap()["Album Artist"].toString()); + m_sAlbumArtist = getQString(ape->itemListMap()["Album Artist"].toString()); } if (ape->itemListMap().contains("Composer")) { - m_sComposer = TStringToQString(ape->itemListMap()["Composer"].toString()); + m_sComposer = getQString(ape->itemListMap()["Composer"].toString()); } if (ape->itemListMap().contains("Grouping")) { - m_sGrouping = TStringToQString(ape->itemListMap()["Grouping"].toString()); + m_sGrouping = getQString(ape->itemListMap()["Grouping"].toString()); } return true; @@ -446,7 +454,7 @@ bool SoundSource::processXiphComment(TagLib::Ogg::XiphComment* xiph) { if (s_bDebugMetadata) { for (TagLib::Ogg::FieldListMap::ConstIterator it = xiph->fieldListMap().begin(); it != xiph->fieldListMap().end(); ++it) { - qDebug() << "XIPH" << TStringToQString((*it).first) << "-" << TStringToQString((*it).second.toString()); + qDebug() << "XIPH" << getQString((*it).first) << "-" << getQString((*it).second.toString()); } } @@ -463,26 +471,26 @@ bool SoundSource::processXiphComment(TagLib::Ogg::XiphComment* xiph) { // Some tags use "BPM" so check for that. if (xiph->fieldListMap().contains("BPM")) { TagLib::StringList bpmString = xiph->fieldListMap()["BPM"]; - QString sBpm = TStringToQString(bpmString.toString()); + QString sBpm = getQString(bpmString.toString()); processBpmString("XIPH-BPM", sBpm); } // Give preference to the "TEMPO" tag which seems to be more standard if (xiph->fieldListMap().contains("TEMPO")) { TagLib::StringList bpmString = xiph->fieldListMap()["TEMPO"]; - QString sBpm = TStringToQString(bpmString.toString()); + QString sBpm = getQString(bpmString.toString()); processBpmString("XIPH-TEMPO", sBpm); } if (xiph->fieldListMap().contains("REPLAYGAIN_ALBUM_GAIN")) { TagLib::StringList rgainString = xiph->fieldListMap()["REPLAYGAIN_ALBUM_GAIN"]; - QString sReplayGain = TStringToQString(rgainString.toString()); + QString sReplayGain = getQString(rgainString.toString()); parseReplayGainString(sReplayGain); } if (xiph->fieldListMap().contains("REPLAYGAIN_TRACK_GAIN")) { TagLib::StringList rgainString = xiph->fieldListMap()["REPLAYGAIN_TRACK_GAIN"]; - QString sReplayGain = TStringToQString(rgainString.toString()); + QString sReplayGain = getQString(rgainString.toString()); parseReplayGainString(sReplayGain); } @@ -496,34 +504,34 @@ bool SoundSource::processXiphComment(TagLib::Ogg::XiphComment* xiph) { */ if (xiph->fieldListMap().contains("KEY")) { TagLib::StringList keyStr = xiph->fieldListMap()["KEY"]; - QString key = TStringToQString(keyStr.toString()); + QString key = getQString(keyStr.toString()); setKey(key); } if (getKey().isEmpty() && xiph->fieldListMap().contains("INITIALKEY")) { TagLib::StringList keyStr = xiph->fieldListMap()["INITIALKEY"]; - QString key = TStringToQString(keyStr.toString()); + QString key = getQString(keyStr.toString()); setKey(key); } if (xiph->fieldListMap().contains("ALBUMARTIST")) { TagLib::StringList albumArtistString = xiph->fieldListMap()["ALBUMARTIST"]; - m_sAlbumArtist = TStringToQString(albumArtistString.toString()); + m_sAlbumArtist = getQString(albumArtistString.toString()); } else { // try alternative field name if (xiph->fieldListMap().contains("ALBUM_ARTIST")) { TagLib::StringList albumArtistString = xiph->fieldListMap()["ALBUM_ARTIST"]; - m_sAlbumArtist = TStringToQString(albumArtistString.toString()); + m_sAlbumArtist = getQString(albumArtistString.toString()); } } if (xiph->fieldListMap().contains("COMPOSER")) { TagLib::StringList composerString = xiph->fieldListMap()["COMPOSER"]; - m_sComposer = TStringToQString(composerString.toString()); + m_sComposer = getQString(composerString.toString()); } if (xiph->fieldListMap().contains("GROUPING")) { TagLib::StringList groupingString = xiph->fieldListMap()["GROUPING"]; - m_sGrouping = TStringToQString(groupingString.toString()); + m_sGrouping = getQString(groupingString.toString()); } return true; @@ -533,8 +541,8 @@ bool SoundSource::processMP4Tag(TagLib::MP4::Tag* mp4) { if (s_bDebugMetadata) { for(TagLib::MP4::ItemListMap::ConstIterator it = mp4->itemListMap().begin(); it != mp4->itemListMap().end(); ++it) { - qDebug() << "MP4" << TStringToQString((*it).first) << "-" - << TStringToQString((*it).second.toStringList().toString()); + qDebug() << "MP4" << getQString((*it).first) << "-" + << getQString((*it).second.toStringList().toString()); } } @@ -551,12 +559,12 @@ bool SoundSource::processMP4Tag(TagLib::MP4::Tag* mp4) { // Get BPM if (mp4->itemListMap().contains("tmpo")) { - QString sBpm = TStringToQString( + QString sBpm = getQString( mp4->itemListMap()["tmpo"].toStringList().toString()); processBpmString("MP4", sBpm); } else if (mp4->itemListMap().contains("----:com.apple.iTunes:BPM")) { // This is an alternate way of storing BPM. - QString sBpm = TStringToQString(mp4->itemListMap()[ + QString sBpm = getQString(mp4->itemListMap()[ "----:com.apple.iTunes:BPM"].toStringList().toString()); processBpmString("MP4", sBpm); } @@ -564,7 +572,7 @@ bool SoundSource::processMP4Tag(TagLib::MP4::Tag* mp4) { // Get Album Artist if (mp4->itemListMap().contains("aART")) { // this is technically a list of values -> concatenate into single string - QString albumArtist = TStringToQString( + QString albumArtist = getQString( mp4->itemListMap()["aART"].toStringList().toString()); setAlbumArtist(albumArtist); } @@ -573,21 +581,21 @@ bool SoundSource::processMP4Tag(TagLib::MP4::Tag* mp4) { if (mp4->itemListMap().contains("\251wrt")) { // rryan 1/2012 I believe this is technically a list of composers. We // don't support multiple composers in Mixxx, so just use them joined. - QString composer = TStringToQString( + QString composer = getQString( mp4->itemListMap()["\251wrt"].toStringList().toString()); setComposer(composer); } // Get Grouping if (mp4->itemListMap().contains("\251grp")) { - QString grouping = TStringToQString( + QString grouping = getQString( mp4->itemListMap()["\251grp"].toStringList().toString()); setGrouping(grouping); } // Get KEY (conforms to Rapid Evolution) if (mp4->itemListMap().contains("----:com.apple.iTunes:KEY")) { - QString key = TStringToQString( + QString key = getQString( mp4->itemListMap()["----:com.apple.iTunes:KEY"].toStringList().toString()); setKey(key); } @@ -598,7 +606,7 @@ bool SoundSource::processMP4Tag(TagLib::MP4::Tag* mp4) { // TODO(XXX) find tracks with this property and check what it looks // like. - //QString replaygain = TStringToQString(mp4->itemListMap()["----:com.apple.iTunes:replaygain_track_gain"].toStringList().toString()); + //QString replaygain = getQString(mp4->itemListMap()["----:com.apple.iTunes:replaygain_track_gain"].toStringList().toString()); } return true; diff --git a/src/soundsource.h b/src/soundsource.h index 265a07b4516..b49fc23835f 100644 --- a/src/soundsource.h +++ b/src/soundsource.h @@ -112,8 +112,8 @@ class SoundSource virtual void setSampleRate(unsigned int); virtual void setChannels(int); virtual void setCoverArt(QImage); -protected: +protected: // Automatically collects generic data from a TagLib File: title, artist, // album, comment, genre, year, tracknumber, duration, bitrate, samplerate, // and channels. @@ -125,6 +125,8 @@ class SoundSource void processBpmString(QString tagName, QString sBpm); void parseReplayGainString(QString sReplayGain); + QString getQString(TagLib::String TString); + /** File name */ QString m_qFilename;