Skip to content

Commit 3f81fc9

Browse files
authored
don't crash for server error. Handle it nicely (#604)
1 parent f25cb50 commit 3f81fc9

File tree

1 file changed

+37
-6
lines changed

1 file changed

+37
-6
lines changed

source/s3_meta_request.c

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1411,13 +1411,34 @@ static int s_s3_meta_request_incoming_headers(
14111411
aws_error_str(aws_last_error()));
14121412
return AWS_OP_ERR;
14131413
} else {
1414+
/* Make we get what we ask for. */
14141415
if (request->part_range_end != 0) {
1415-
AWS_FATAL_ASSERT(request->part_range_start == object_range_start);
1416+
if (request->part_range_start != object_range_start) {
1417+
/* Log the error */
1418+
AWS_LOGF_ERROR(
1419+
AWS_LS_S3_META_REQUEST,
1420+
"id=%p: Part range start mismatch. Expected: %" PRIu64 ", Actual: %" PRIu64 "",
1421+
(void *)meta_request,
1422+
request->part_range_start,
1423+
object_range_start);
1424+
return aws_raise_error(AWS_ERROR_S3_INVALID_CONTENT_RANGE_HEADER);
1425+
}
14161426
if (request->part_range_end != object_range_end) {
1417-
/* In the case where the object size is less than the range requested, it will return the bytes
1418-
* to the object size. Range is inclusive */
1419-
AWS_FATAL_ASSERT(object_range_start + object_size - 1 == object_range_end);
1420-
AWS_FATAL_ASSERT(request->part_range_end > object_range_end);
1427+
/* In the case where the object size is less than the range requested. It must be return the
1428+
* last part to the end of the object. */
1429+
if (object_size != object_range_end + 1 || request->part_range_end < object_range_end) {
1430+
/* Something went wrong if it's matching. Log the error. */
1431+
AWS_LOGF_ERROR(
1432+
AWS_LS_S3_META_REQUEST,
1433+
"id=%p: Part range end mismatch. Expected: %" PRIu64 ", Actual: %" PRIu64
1434+
", while object size is: "
1435+
"%" PRIu64 ".",
1436+
(void *)meta_request,
1437+
request->part_range_end,
1438+
object_range_end,
1439+
object_size);
1440+
return aws_raise_error(AWS_ERROR_S3_INVALID_CONTENT_RANGE_HEADER);
1441+
}
14211442
}
14221443
}
14231444
}
@@ -2059,7 +2080,17 @@ static void s_s3_meta_request_event_delivery_task(struct aws_task *task, void *a
20592080
meta_request->io_threaded_data.next_deliver_range_start = delivery_range_start;
20602081
}
20612082
/* Make sure the response body is delivered in the sequential order */
2062-
AWS_FATAL_ASSERT(delivery_range_start == meta_request->io_threaded_data.next_deliver_range_start);
2083+
if (delivery_range_start != meta_request->io_threaded_data.next_deliver_range_start) {
2084+
/* Unexpected error, log the error */
2085+
AWS_LOGF_ERROR(
2086+
AWS_LS_S3_META_REQUEST,
2087+
"id=%p: Unexpected code error. Please report the error to the team, "
2088+
"delivery_range_start:%" PRIu64 ", next_deliver_range_start:%" PRIu64 ".",
2089+
(void *)meta_request,
2090+
delivery_range_start,
2091+
meta_request->io_threaded_data.next_deliver_range_start);
2092+
error_code = AWS_ERROR_INVALID_STATE;
2093+
}
20632094
meta_request->io_threaded_data.next_deliver_range_start += response_body.len;
20642095

20652096
if (error_code == AWS_ERROR_SUCCESS && response_body.len > 0) {

0 commit comments

Comments
 (0)