Browse Source

After Issue 2403 (d56df35b) the request structure is too big for stack

And max header count is insanely big too

Source commit: 415329f1d0ea286c9b2090efeb48496304432850
Martin Prikryl 1 week ago
parent
commit
b7d6fd3003
3 changed files with 9 additions and 12 deletions
  1. 2 6
      libs/libs3/inc/libs3.h
  2. 1 2
      libs/libs3/inc/util.h
  3. 6 4
      libs/libs3/src/request.c

+ 2 - 6
libs/libs3/inc/libs3.h

@@ -174,13 +174,9 @@ extern "C" {
 
 /**
  * S3_MAX_METADATA_COUNT is the maximum number of x-amz-meta- headers that
- * could be included in a request to S3.  The smallest meta header is
- * "x-amz-meta-n: v".  Since S3 doesn't count the ": " against the total, the
- * smallest amount of data to count for a header would be the length of
- * "x-amz-meta-nv".
+ * could be included in a request to S3.
  **/
-#define S3_MAX_METADATA_COUNT \
-    (S3_MAX_METADATA_SIZE / (sizeof(S3_METADATA_HEADER_NAME_PREFIX "nv") - 1))
+#define S3_MAX_METADATA_COUNT 128
 
 
 /**

+ 1 - 2
libs/libs3/inc/util.h

@@ -52,8 +52,7 @@
 
 // This is the maximum number of bytes needed in a "compacted meta header"
 // buffer, which is a buffer storing all of the compacted meta headers.
-#define COMPACTED_METADATA_BUFFER_SIZE \
-    (S3_MAX_METADATA_COUNT * sizeof(S3_METADATA_HEADER_NAME_PREFIX "n: v"))
+#define COMPACTED_METADATA_BUFFER_SIZE S3_MAX_METADATA_SIZE // WINSCP
 
 // Maximum url encoded key size; since every single character could require
 // URL encoding, it's 3 times the size of a key (since each url encoded

+ 6 - 4
libs/libs3/src/request.c

@@ -55,6 +55,7 @@
 
 #ifdef WINSCP
 #define SIGNATURE_DEBUG
+#include <memory>
 #endif
 
 static char userAgentG[USER_AGENT_SIZE];
@@ -413,7 +414,7 @@ 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];
+            char byteRange[64];
             snprintf(byteRange, sizeof(byteRange), "bytes=%zd-%zd",
                      params->startByte, params->startByte + params->byteCount);
             append_amz_header(values, 0, "x-amz-copy-source-range", byteRange);
@@ -1618,14 +1619,15 @@ void request_perform(const RequestParams *params, S3RequestContext *context)
     return
 
     // These will hold the computed values
-    RequestComputedValues computed;
+    // WINSCP: too big for stack
+    std::unique_ptr<RequestComputedValues> computed(new RequestComputedValues());
 
-    if ((status = setup_request(params, &computed, 0, context->requesterPays)) != S3StatusOK) { // WINSCP
+    if ((status = setup_request(params, computed.get(), 0, context->requesterPays)) != S3StatusOK) { // WINSCP
         return_status(status);
     }
 
     // Get an initialized Request structure now
-    if ((status = request_get(params, &computed, context, &request)) != S3StatusOK) {
+    if ((status = request_get(params, computed.get(), context, &request)) != S3StatusOK) {
         return_status(status);
     }
     // WINSCP (we should always verify the peer)