Skip to content

Commit e6a395b

Browse files
committed
add checks for the response to match the request and makes sure the data delivery in the sequential order
1 parent 72e6976 commit e6a395b

File tree

3 files changed

+33
-5
lines changed

3 files changed

+33
-5
lines changed

include/aws/s3/private/s3_meta_request_impl.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,9 @@ struct aws_s3_meta_request {
277277
* This is an optimization, we could have just copied the array when the task runs,
278278
* but swapping two array-lists back and forth avoids an allocation. */
279279
struct aws_array_list event_delivery_array;
280+
281+
/* The range start for the next response body delivery */
282+
uint64_t next_deliver_range_start;
280283
} io_threaded_data;
281284

282285
const bool should_compute_content_md5;

source/s3_auto_ranged_get.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -810,8 +810,11 @@ static void s_s3_auto_ranged_get_request_finished(
810810
auto_ranged_get->estimated_object_stored_part_size);
811811
} else {
812812
/* Failed to parse ETags */
813-
aws_raise_error(AWS_ERROR_S3_MISSING_ETAG);
814-
error_code = AWS_ERROR_S3_MISSING_ETAG;
813+
AWS_LOGF_WARN(
814+
AWS_LS_S3_META_REQUEST,
815+
"id=%p Failed to parse ETags, fallback to default part size.",
816+
(void *)meta_request);
817+
auto_ranged_get->estimated_object_stored_part_size = g_default_part_size_fallback;
815818
goto update_synced_data;
816819
}
817820
}

source/s3_meta_request.c

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1284,7 +1284,8 @@ static bool s_header_value_from_list(
12841284
return false;
12851285
}
12861286

1287-
static void s_get_part_response_headers_checksum_helper(
1287+
/* Return if we found the checksum from headers or not. */
1288+
static bool s_get_part_response_headers_checksum_helper(
12881289
struct aws_s3_connection *connection,
12891290
struct aws_s3_meta_request *meta_request,
12901291
const struct aws_http_header *headers,
@@ -1308,9 +1309,10 @@ static void s_get_part_response_headers_checksum_helper(
13081309
aws_checksum_new(meta_request->allocator, algorithm);
13091310
AWS_ASSERT(connection->request->request_level_running_response_sum != NULL);
13101311
}
1311-
break;
1312+
return true;
13121313
}
13131314
}
1315+
return false;
13141316
}
13151317

13161318
static int s_s3_meta_request_incoming_headers(
@@ -1355,10 +1357,27 @@ static int s_s3_meta_request_incoming_headers(
13551357

13561358
if (successful_response && meta_request->checksum_config.validate_response_checksum &&
13571359
request->request_type == AWS_S3_REQUEST_TYPE_GET_OBJECT) {
1358-
/* We have `struct aws_http_header *` array instead of `struct aws_http_headers *` :) */
1360+
/* We have `struct aws_http_header *` array instead of `struct aws_http_headers *` */
13591361
s_get_part_response_headers_checksum_helper(connection, meta_request, headers, headers_count);
13601362
}
13611363

1364+
#if DEBUG_BUILD
1365+
/* Only perform this validation during debug build, since it's a programming bug and "expensive" for each response
1366+
* received */
1367+
if (successful_response && request->request_type == AWS_S3_REQUEST_TYPE_GET_OBJECT) {
1368+
uint64_t object_size = 0;
1369+
uint64_t object_range_start = 0;
1370+
uint64_t object_range_end = 0;
1371+
if (aws_s3_parse_content_range_response_header(
1372+
meta_request->allocator, headers, &object_range_start, &object_range_end, &object_size) ==
1373+
AWS_OP_SUCCESS) {
1374+
/* Validate that the content-range response matches the request. */
1375+
AWS_ASSERT(request->part_range_start == object_range_start);
1376+
AWS_ASSERT(request->part_range_end == object_range_end);
1377+
}
1378+
}
1379+
#endif /* DEBUG_BUILD */
1380+
13621381
/* Only record headers if an error has taken place, or if the request_desc has asked for them. */
13631382
bool should_record_headers = !successful_response || request->record_response_headers;
13641383

@@ -1963,6 +1982,9 @@ static void s_s3_meta_request_event_delivery_task(struct aws_task *task, void *a
19631982
struct aws_byte_cursor response_body = aws_byte_cursor_from_buf(&request->send_data.response_body);
19641983

19651984
AWS_ASSERT(request->part_number >= 1);
1985+
/* Make sure the response body is delivered in the sequential order */
1986+
AWS_FATAL_ASSERT(request->part_range_start == meta_request->io_threaded_data.next_deliver_range_start);
1987+
meta_request->io_threaded_data.next_deliver_range_start += response_body.len;
19661988

19671989
if (error_code == AWS_ERROR_SUCCESS && response_body.len > 0) {
19681990
if (meta_request->meta_request_level_running_response_sum) {

0 commit comments

Comments
 (0)