Fix CopyObject panic when X-Amz-Copy-Source is fully URL-encoded#119
Open
rjpr wants to merge 1 commit into
Open
Fix CopyObject panic when X-Amz-Copy-Source is fully URL-encoded#119rjpr wants to merge 1 commit into
rjpr wants to merge 1 commit into
Conversation
Some S3 clients (notably AWS SDK v2 for Go) may URL-encode the entire X-Amz-Copy-Source header value, including the "/" separator between bucket and key as "%2F". This caused a panic when trying to access parts[1] after splitting by "/", since the split produced only one element. This fix: 1. Attempts to split the source as-is (existing behavior) 2. If that fails (<2 parts), URL-decodes the source and tries again 3. Tracks whether decoding occurred to avoid double-decoding the key (which would corrupt "+" characters by converting them to spaces) Added tests for: - Fully URL-encoded source path (the panic case) - Fully URL-encoded source with special chars like "+" and spaces Fixes index out of range panic: panic: runtime error: index out of range [1] with length 1
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.




CopyObject panics with an index out of range when the X-Amz-Copy-Source header is fully URL-encoded:
The S3 API documentation requires the x-amz-copy-source header value to be URL-encoded, but is ambiguous about whether the "/" separating bucket and key should be encoded. Some clients encode only the key (bucket/src%2Bkey) while others encode the entire value, including the separator as "%2F" (bucket%2Fsrc%2Bkey).
gofakes3 only handles the first format, it splits on a literal "/" before URL-decoding, so a fully-encoded value produces a single-element slice, causing the panic.
This PR:
Tests added: