Skip to content

Commit

Permalink
Fix CopyObject for CopySource containing a key with slashes
Browse files Browse the repository at this point in the history
When attempting to use CopyObject with a CopySource key containing slashes
such as bar/baz/mypic.jpg S3Ninja returns an error:

"sirius.kernel.health.HandledException: An error occurred: Bucket name
"mybucket/bar/baz"; does not adhere to the rules.
[https://docs.aws.amazon.com/AmazonS3/latest/dev/BucketRestrictions.html]"

The problem is that S3Dispatcher's copyObject() doesn't correctly parse
the bucket name and key from x-amz-copy-source as
copy.lastIndexOf(PATH_DELIMITER) returns the index of the last separator
in the key, rather than the index of first separator after the bucket
name.

Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
  • Loading branch information
mcayland committed Jan 26, 2023
1 parent ddd03de commit 54fe099
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/main/java/ninja/S3Dispatcher.java
Expand Up @@ -734,8 +734,8 @@ private void copyObject(WebContext webContext, Bucket bucket, String id, String
String.format("Source '%s' must contain '/'", copy));
return;
}
String srcBucketName = copy.substring(1, copy.lastIndexOf(PATH_DELIMITER));
String srcId = copy.substring(copy.lastIndexOf(PATH_DELIMITER) + 1);
String srcBucketName = copy.substring(1, copy.indexOf(PATH_DELIMITER, 1));
String srcId = copy.substring(copy.indexOf(PATH_DELIMITER, 1) + 1);
Bucket srcBucket = storage.getBucket(srcBucketName);
if (!srcBucket.exists()) {
signalObjectError(webContext,
Expand Down

0 comments on commit 54fe099

Please sign in to comment.