Skip to content

Commit c44f6be

Browse files
committed
don't crash for server error. Handle it nicely
1 parent f25cb50 commit c44f6be

File tree

1 file changed

+26
-5
lines changed

1 file changed

+26
-5
lines changed

source/s3_meta_request.c

Lines changed: 26 additions & 5 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
}

0 commit comments

Comments
 (0)