From 20002ce937851f65fb7aeb5ae044fa6e2fb38821 Mon Sep 17 00:00:00 2001 From: Jakob Breivik Grimstveit Date: Fri, 11 Sep 2026 01:06:46 +0200 Subject: [PATCH] Fix false invalid session error on empty URI Avoid triggering 'Session data is invalid' when loading downloads with an empty URI. --- src/core/download_factory.cc | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/src/core/download_factory.cc b/src/core/download_factory.cc index a243066c..74c548dc 100644 --- a/src/core/download_factory.cc +++ b/src/core/download_factory.cc @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -39,6 +40,11 @@ static constexpr const char* session_invalid_message = "Session data is invalid, static std::unique_ptr download_factory_load_stream(const char* filename, bool* is_invalid) { + struct stat sb; + + if (stat(filename, &sb) != 0 || !S_ISREG(sb.st_mode)) + return std::unique_ptr(); + std::fstream stream(filename, std::ios::in | std::ios::binary); if (!stream.is_open()) @@ -167,11 +173,19 @@ void DownloadFactory::receive_success() { bool session_invalid = false; - auto rtorrent_object = download_factory_load_stream((expand_path(m_uri) + ".rtorrent").c_str(), &session_invalid); - auto libtorrent_resume_object = download_factory_load_stream((expand_path(m_uri) + ".libtorrent_resume").c_str(), &session_invalid); + std::unique_ptr rtorrent_object; + std::unique_ptr libtorrent_resume_object; - if (session_invalid) - lt_log_print(torrent::LOG_ERROR, "%s: %s", session_invalid_message, m_uri.c_str()); + if (m_session) { + if (m_uri.empty()) + throw torrent::input_error("Session torrent URI is empty."); + + rtorrent_object = download_factory_load_stream((expand_path(m_uri) + ".rtorrent").c_str(), &session_invalid); + libtorrent_resume_object = download_factory_load_stream((expand_path(m_uri) + ".libtorrent_resume").c_str(), &session_invalid); + + if (session_invalid) + lt_log_print(torrent::LOG_ERROR, "%s: %s", session_invalid_message, m_uri.c_str()); + } uint32_t tracker_key;