From 50b50e5c623a6fb0cb65d7616118b902c46000d7 Mon Sep 17 00:00:00 2001 From: Martin Prikryl Date: Mon, 15 Mar 2021 12:54:06 +0100 Subject: [PATCH] Key in x-amz-copy-source header must be URL-encoded --- src/request.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/request.c b/src/request.c index dd66863..141e8d8 100644 --- a/src/request.c +++ b/src/request.c @@ -393,9 +393,12 @@ static S3Status compose_amz_headers(const RequestParams *params, // Add the x-amz-copy-source header if (params->copySourceBucketName && params->copySourceBucketName[0] && params->copySourceKey && params->copySourceKey[0]) { - char bucketKey[S3_MAX_METADATA_SIZE]; - snprintf(bucketKey, sizeof(bucketKey), "/%s/%s", - params->copySourceBucketName, params->copySourceKey); + char bucketKey[1 + S3_MAX_BUCKET_NAME_SIZE + 1 + MAX_URLENCODED_KEY_SIZE + 1]; + snprintf(bucketKey, 1 + S3_MAX_BUCKET_NAME_SIZE + 1 + 1, "/%s/", params->copySourceBucketName); + if (!urlEncode(bucketKey + strlen(bucketKey), params->copySourceKey, S3_MAX_KEY_SIZE, 0)) + { + return S3StatusUriTooLong; + } append_amz_header(values, 0, "x-amz-copy-source", bucketKey); } // If byteCount != 0 then we're just copying a range, add header