Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

64-bit unsafely in GET range request #103

Open
pjd-nu opened this issue Oct 13, 2020 · 1 comment
Open

64-bit unsafely in GET range request #103

pjd-nu opened this issue Oct 13, 2020 · 1 comment

Comments

@pjd-nu
Copy link

pjd-nu commented Oct 13, 2020

startByte should be an 8-byte value, not 4 bytes.

--- a/inc/request.h
+++ b/inc/request.h
@@ -81,7 +81,7 @@ typedef struct RequestParams
     const S3GetConditions *getConditions;
 
     // Start byte
-    size_t startByte;
+    off_t startByte;
 
     // Byte count
     size_t byteCount;
diff --git a/src/request.c b/src/request.c
index dd66863..ea01c82 100644
--- a/src/request.c
+++ b/src/request.c
@@ -401,8 +401,9 @@ static S3Status compose_amz_headers(const RequestParams *params,
         // If byteCount != 0 then we're just copying a range, add header
         if (params->byteCount > 0) {
             char byteRange[S3_MAX_METADATA_SIZE];
-            snprintf(byteRange, sizeof(byteRange), "bytes=%zd-%zd",
-                     params->startByte, params->startByte + params->byteCount);
+            snprintf(byteRange, sizeof(byteRange), "bytes=%lld-%lld",
+                     (long long)params->startByte,
+                     (long long)params->startByte + params->byteCount);
             append_amz_header(values, 0, "x-amz-copy-source-range", byteRange);
         }
         // And the x-amz-metadata-directive header
@pjd-nu
Copy link
Author

pjd-nu commented Oct 16, 2020

Note that this isn't a problem on platforms where sizeof(size_t) == 8, but for Linux on 32-bit Intel it's broken.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant