Skip to content

rgw: Check if HTTP_X_AMZ_COPY_SOURCE header is empty - #65159

Merged
yuvalif merged 1 commit into
ceph:mainfrom
Suyashd999:fix-check-source-header
Oct 22, 2025
Merged

yuvalif merged 1 commit into
ceph:mainfrom
Suyashd999:fix-check-source-header

Conversation

@Suyashd999

@Suyashd999 Suyashd999 commented Aug 20, 2025 •

Copy link
Copy Markdown
Contributor

The issue was that the HTTP_X_AMZ_COPY_SOURCE header could be present but empty (i.e., an empty string rather than NULL). The code only checked if the pointer was not NULL, but didn't verify that the string had content. When an empty string was passed to RGWCopyObj::parse_copy_location(), it would eventually try to access name_str[0] on an empty string, causing a crash.

Fixes: https://tracker.ceph.com/issues/72669 (cbodley edited to fix the link)

Contribution Guidelines

  • To sign and title your commits, please refer to Submitting Patches to Ceph.

  • If you are submitting a fix for a stable branch (e.g. "quincy"), please refer to Submitting Patches to Ceph - Backports for the proper workflow.

  • When filling out the below checklist, you may click boxes directly in the GitHub web UI. When entering or editing the entire PR message in the GitHub web UI editor, you may also select a checklist item by adding an x between the brackets: [x]. Spaces and capitalization matter when checking off items this way.

Checklist

  • Tracker (select at least one)
    • References tracker ticket
    • Very recent bug; references commit where it was introduced
    • New feature (ticket optional)
    • Doc update (no ticket needed)
    • Code cleanup (no ticket needed)
  • Component impact
    • Affects Dashboard, opened tracker ticket
    • Affects Orchestrator, opened tracker ticket
    • No impact that needs to be tracked
  • Documentation (select at least one)
    • Updates relevant documentation
    • No doc update is appropriate
  • Tests (select at least one)
Show available Jenkins commands

@Suyashd999
Suyashd999 requested a review from a team as a code owner August 20, 2025 19:34
@github-actions github-actions Bot added the rgw label Aug 20, 2025
@Suyashd999
Suyashd999 force-pushed the fix-check-source-header branch 2 times, most recently from 026beb9 to e1243c8 Compare August 20, 2025 19:37
Comment thread src/rgw/rgw_op.cc Outdated
if (name_str[0] == '/') // trim leading slash
if (!name_str.empty() && name_str[0] == '/') // trim leading slash

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks. https://en.cppreference.com/w/cpp/string/basic_string_view/remove_prefix does say that name_str.remove_prefix(1) is undefined behavior if name_str is empty, so this looks correct 👍

but ultimately an empty name_str should cause us to return false below:

  pos = dec_src.find('/');
  if (pos == string::npos)
    return false;

so i'd suggest that we instead add an early return for name_str.empty() before this line:

+  if (name_str.empty()) {
+    return false;
+  }
   if (name_str[0] == '/') // trim leading slash

does that look right to you?

Comment thread src/rgw/rgw_rest_s3.cc Outdated
@@ -4995,7 +4995,7 @@ int RGWHandler_REST_S3::init(rgw::sal::Driver* driver, req_state *s,
s->has_acl_header = s->info.env->exists_prefix("HTTP_X_AMZ_GRANT");

const char *copy_source = s->info.env->get("HTTP_X_AMZ_COPY_SOURCE");
if (copy_source &&
if (copy_source && copy_source[0] != '\0' &&

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this change necessary? if the client sends an empty x-amz-copy-source header, this function should still treat it as a copy request and catch the error from parse_copy_location() just below. but your change will cause us to skip this block and continue on with a null s->src_object. that might cause us to crash or misbehave later in the request processing

@adamemerson

Copy link
Copy Markdown
Contributor

@Suyashd999 Did you get a chance to make the changes Casey requested?

The issue was that the `HTTP_X_AMZ_COPY_SOURCE` header could be present but empty (i.e., an empty string rather than NULL). The  code only checked if the pointer was not NULL, but didn't verify that the string had content. When an empty string was passed to RGWCopyObj::parse_copy_location(), it would eventually try to access name_str[0] on an empty string, causing a crash.

Fixes: https://tracker.ceph.com/issues/72669

Signed-off-by: Suyash Dongre <[email protected]>
@Suyashd999
Suyashd999 force-pushed the fix-check-source-header branch from e1243c8 to bef59f1 Compare September 25, 2025 09:53
@Suyashd999
Suyashd999 requested a review from cbodley September 25, 2025 09:54
@yuvalif

yuvalif commented Sep 25, 2025

Copy link
Copy Markdown
Contributor

jenkins test api

@anrao19

anrao19 commented Oct 22, 2025

Copy link
Copy Markdown
Contributor

pr testing completed and approved by @ivancich. Please find the details : https://tracker.ceph.com/issues/73371
@Suyashd999 , if there is not further testing needed this can be merged. Please let me know

@occamist

occamist commented Dec 11, 2025 •

Copy link
Copy Markdown

has anyone raised the issue of whitespaces such as " " ? I would suggest using boost::trim at least before the check?

@yuvalif

yuvalif commented Dec 14, 2025

Copy link
Copy Markdown
Contributor

has anyone raised the issue of whitespaces such as " " ? I would suggest using boost::trim at least before the check?

@mrwormhole will it be crashing the RGW? if so, please open a tracker for that

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants