From a1181f2f87ce12f1a015fdded212f1266b33c5a8 Mon Sep 17 00:00:00 2001 From: casey langen Date: Wed, 21 Dec 2022 15:52:23 -0800 Subject: [PATCH] Guard against known-invalid-input to avoid exception. --- src/musikcore/library/track/IndexerTrack.cpp | 6 ++++-- src/plugins/taglib_plugin/TaglibMetadataReader.cpp | 7 ++++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/musikcore/library/track/IndexerTrack.cpp b/src/musikcore/library/track/IndexerTrack.cpp index b9fdc4b27..e6a91a122 100644 --- a/src/musikcore/library/track/IndexerTrack.cpp +++ b/src/musikcore/library/track/IndexerTrack.cpp @@ -304,11 +304,13 @@ bool IndexerTrack::NeedsToBeIndexed( static int stringToInt(const std::string& str, const int defaultValue) { try { - return std::stoi(str, 0, 10); + if (str.size()) { + return std::stoi(str, 0, 10); + } } catch (...) { - return defaultValue; } + return defaultValue; } static int64_t writeToTracksTable( diff --git a/src/plugins/taglib_plugin/TaglibMetadataReader.cpp b/src/plugins/taglib_plugin/TaglibMetadataReader.cpp index cc8572352..f9f348aba 100644 --- a/src/plugins/taglib_plugin/TaglibMetadataReader.cpp +++ b/src/plugins/taglib_plugin/TaglibMetadataReader.cpp @@ -146,7 +146,12 @@ static TagLib::FileRef resolveOggType(const char* uri) { } static bool isValidYear(const std::string& year) { - return std::stoi(year) > 0; + try { + return year.size() && std::stoi(year) > 0; + } + catch (...) { + } + return false; } static float toReplayGainFloat(const std::string& input) {