From 0094772912a7befc3867bc05f3b81229a68153c0 Mon Sep 17 00:00:00 2001 From: Kannibal Ox Date: Sun, 18 Dec 2022 16:27:37 -0500 Subject: [PATCH 1/2] Move base64 data parsing to happen under load.raw I remarked on this deviation from vanilla rTorrent #52, but just worked around it since my code already required changes for JSON-RPC anyway. --- src/core/manager.cc | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/core/manager.cc b/src/core/manager.cc index 5f9146a9..1074597c 100644 --- a/src/core/manager.cc +++ b/src/core/manager.cc @@ -439,15 +439,17 @@ Manager::try_create_download(const std::string& uri, } if (flags & create_raw_data) { - f->load_raw_data(uri); - } else if (is_data_uri(uri)) { - const unsigned long start = uri.find("base64,", 5) + 7; - if (start >= uri.size()) { - throw torrent::input_error("Empty base64."); - } + if (is_data_uri(uri)) { + const unsigned long start = uri.find("base64,", 5) + 7; + if (start >= uri.size()) { + throw torrent::input_error("Empty base64."); + } - f->load_raw_data(base64Decode(std::string_view(uri.c_str() + start))); - f->variables()["tied_to_file"] = (int64_t)0; + f->load_raw_data(base64Decode(std::string_view(uri.c_str() + start))); + f->variables()["tied_to_file"] = (int64_t)0; + } else { + f->load_raw_data(uri); + } } else { f->load(uri); } From fed550ca2933a6c4ca2d8f82b744115b8ef82a35 Mon Sep 17 00:00:00 2001 From: Kannibal Ox Date: Mon, 3 Jul 2023 21:20:47 -0400 Subject: [PATCH 2/2] Allow base64 data in both load calls --- src/core/manager.cc | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/src/core/manager.cc b/src/core/manager.cc index 1074597c..c5202b6a 100644 --- a/src/core/manager.cc +++ b/src/core/manager.cc @@ -438,18 +438,17 @@ Manager::try_create_download(const std::string& uri, f->slot_finished([f]() { delete f; }); } - if (flags & create_raw_data) { - if (is_data_uri(uri)) { - const unsigned long start = uri.find("base64,", 5) + 7; - if (start >= uri.size()) { - throw torrent::input_error("Empty base64."); - } - - f->load_raw_data(base64Decode(std::string_view(uri.c_str() + start))); - f->variables()["tied_to_file"] = (int64_t)0; - } else { - f->load_raw_data(uri); + // Handle base64 data regardless of whether the flag is set for raw, + // for backwards compatibility + if (is_data_uri(uri)) { + const unsigned long start = uri.find("base64,", 5) + 7; + if (start >= uri.size()) { + throw torrent::input_error("Empty base64."); } + f->load_raw_data(base64Decode(std::string_view(uri.c_str() + start))); + f->variables()["tied_to_file"] = (int64_t)0; + } else if (flags & create_raw_data) { + f->load_raw_data(uri); } else { f->load(uri); }