From: Emin Date: Mon, 26 May 2025 14:11:19 +0000 (+0200) Subject: fix: remove double url_decode from the copy_source and fix url_decode X-Git-Tag: v19.2.3~13^2~2 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=b20a71f9c8800cf5749c8aff3e08ba62ad51cc79;p=ceph.git fix: remove double url_decode from the copy_source and fix url_decode Signed-off-by: Emin (cherry picked from commit 1510987b8606d8906ba53d4f343a788209707bcf) --- diff --git a/src/rgw/rgw_common.cc b/src/rgw/rgw_common.cc index 33b6416867772..3ba07361c19f6 100644 --- a/src/rgw/rgw_common.cc +++ b/src/rgw/rgw_common.cc @@ -1723,13 +1723,14 @@ std::string url_decode(const std::string_view& src_str, bool in_query) const char c1 = hex_to_num(*src++); const char c2 = hex_to_num(*src); if (c1 < 0 || c2 < 0) { - return std::string(); + src--; + src--; //going back to the % + dest_str.push_back(*src); //add % to the target destination string } else { dest_str.push_back(c1 << 4 | c2); } } } - return dest_str; } diff --git a/src/rgw/rgw_op.cc b/src/rgw/rgw_op.cc index 2b580236ced7f..2c0076b47d3c7 100644 --- a/src/rgw/rgw_op.cc +++ b/src/rgw/rgw_op.cc @@ -3820,16 +3820,14 @@ int RGWPutObj::init_processing(optional_yield y) { copy_source_bucket_name = copy_source_bucket_name.substr(0, pos); #define VERSION_ID_STR "?versionId=" pos = copy_source_object_name.find(VERSION_ID_STR); - if (pos == std::string::npos) { - copy_source_object_name = url_decode(copy_source_object_name); - } else { + if (pos != std::string::npos) { copy_source_version_id = copy_source_object_name.substr(pos + sizeof(VERSION_ID_STR) - 1); copy_source_object_name = - url_decode(copy_source_object_name.substr(0, pos)); + copy_source_object_name.substr(0, pos); } if (copy_source_object_name.empty()) { - //means url_decode returned empty string so the url is formatted badly + //means copy_source_object_name is empty string so the url is formatted badly ret = -EINVAL; ldpp_dout(this, 5) << "x-amz-copy-source bad format" << dendl; return ret;