From f805a28081bb2017c7ca850a337b43b9476b6ade Mon Sep 17 00:00:00 2001 From: _ <🐱> Date: Sun, 29 Nov 2020 15:17:19 -0700 Subject: [PATCH] Better bounds checking and error handling when downloading --- SpotifyKeyDumper/Utils.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/SpotifyKeyDumper/Utils.cpp b/SpotifyKeyDumper/Utils.cpp index 6c8f2a1..5ccde29 100644 --- a/SpotifyKeyDumper/Utils.cpp +++ b/SpotifyKeyDumper/Utils.cpp @@ -140,7 +140,13 @@ void Utils::DownloadSong(std::string fileId, std::string trackUri, std::string k std::string srStr = DownloadSpotifyUrl("spclient.wg.spotify.com", "/storage-resolve/files/audio/interactive_prefetch/" + fileId + "?product=0", authToken); - if (srStr.length() > 5 && srStr.substr(0, 5).compare("Error") == 0) + if (srStr.length() <= 5) + { + std::cout << "Error: Couldn't fetch storage resolve!" << std::endl; + return; + } + + if (srStr.substr(0, 5).compare("Error") == 0) { std::cout << srStr << std::endl; return; @@ -174,13 +180,13 @@ void Utils::DownloadSong(std::string fileId, std::string trackUri, std::string k // Download encrypted song data from Spotify std::string songStr = DownloadSpotifyUrl(songHost, songPath, ""); - if (songStr.empty()) + if (songStr.length() <= 6) { - std::cout << "Error: Could not download audio" << std::endl; + std::cout << "Error: Could not download audio!" << std::endl; return; } - if (songStr.length() > 6 && songStr.substr(0, 6).compare("") == 0) + if (songStr.substr(0, 6).compare("") == 0) { std::cout << "Error: " + songStr << std::endl; return;