From 422b5a70240d4456fd1fd1b7de82bb937c823556 Mon Sep 17 00:00:00 2001 From: Sebastien Tardif Date: Mon, 8 Jun 2026 12:04:03 -0700 Subject: [PATCH] fix: prevent panic in ParseCopySource on empty input ParseCopySource indexes into copySourceHeader[0] without checking for an empty string, causing an index-out-of-range panic. The three backend callers (azure, posix) pass the x-amz-copy-source header value directly, so a malformed or missing header propagates an empty string into ParseCopySource. Add an empty-string guard at the top of the function that returns an InvalidArgCopySourceBucket error, consistent with the existing error returned when the source path has no bucket/object separator. Add a table-driven test case that reproduces the panic without the fix and verifies the correct error with the fix. Signed-off-by: Sebastien Tardif --- backend/common.go | 4 ++++ backend/common_test.go | 9 +++++++++ 2 files changed, 13 insertions(+) diff --git a/backend/common.go b/backend/common.go index 8ffb71bc..baa22307 100644 --- a/backend/common.go +++ b/backend/common.go @@ -230,6 +230,10 @@ func ParseCopySourceRange(size int64, acceptRange string) (int64, int64, error) // ParseCopySource parses x-amz-copy-source header and returns source bucket, // source object, versionId, error respectively func ParseCopySource(copySourceHeader string) (string, string, string, error) { + if copySourceHeader == "" { + return "", "", "", s3err.GetInvalidArgumentErr(s3err.InvalidArgCopySourceBucket, copySourceHeader) + } + if copySourceHeader[0] == '/' { copySourceHeader = copySourceHeader[1:] } diff --git a/backend/common_test.go b/backend/common_test.go index 993a7d8d..fa69eb66 100644 --- a/backend/common_test.go +++ b/backend/common_test.go @@ -223,6 +223,15 @@ func TestParseCopySource(t *testing.T) { wantErr: true, wantErrValue: s3err.GetInvalidArgumentErr(s3err.InvalidArgCopySourceEncoding, "mybucket/object%ZZ"), }, + { + name: "empty string", + copySourceHeader: "", + wantBucket: "", + wantObject: "", + wantVersionId: "", + wantErr: true, + wantErrValue: s3err.GetInvalidArgumentErr(s3err.InvalidArgCopySourceBucket, ""), + }, { name: "missing object", copySourceHeader: "mybucket",