Skip to content

Commit cccbab5

Browse files
fuzz fix
1 parent f080353 commit cccbab5

4 files changed

Lines changed: 15 additions & 2 deletions

File tree

include/aws/s3/private/s3_default_buffer_pool.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ struct aws_s3_default_buffer_pool_usage_stats {
4444
/* Max size of buffer to be allocated from primary. */
4545
size_t primary_cutoff;
4646

47+
/* Min size of buffer to be allocated from primary. */
48+
size_t primary_min_cutoff;
49+
4750
/* Overall memory allocated for blocks. */
4851
size_t primary_allocated;
4952
/* Number of blocks allocated in primary. */

source/s3_default_buffer_pool.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -896,6 +896,7 @@ struct aws_s3_default_buffer_pool_usage_stats aws_s3_default_buffer_pool_get_usa
896896
struct aws_s3_default_buffer_pool_usage_stats ret = (struct aws_s3_default_buffer_pool_usage_stats){
897897
.mem_limit = buffer_pool->mem_limit,
898898
.primary_cutoff = buffer_pool->primary_size_cutoff,
899+
.primary_min_cutoff = buffer_pool->primary_size_min_cutoff,
899900
.primary_allocated = buffer_pool->primary_allocated,
900901
.primary_used = buffer_pool->primary_used,
901902
.primary_reserved = buffer_pool->primary_reserved,

source/s3_meta_request.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1430,7 +1430,11 @@ static int s_s3_meta_request_incoming_headers(
14301430
* optimistically allocate part sized buffer, and see if its enough. If its over, the req will
14311431
* get canceled. So in that case skip validation on expected size.
14321432
*/
1433-
if (request->request_tag != AWS_S3_AUTO_RANGE_GET_REQUEST_TYPE_GET_OBJECT_WITH_PART_NUMBER_1 &&
1433+
bool is_unknown_len_part_req =
1434+
request->request_type == AWS_S3_REQUEST_TYPE_GET_OBJECT &&
1435+
request->request_tag != AWS_S3_AUTO_RANGE_GET_REQUEST_TYPE_GET_OBJECT_WITH_PART_NUMBER_1;
1436+
1437+
if ( !is_unknown_len_part_req &&
14341438
(object_size != object_range_end + 1 || request->part_range_end < object_range_end)) {
14351439
/* Something went wrong if it's matching. Log the error. */
14361440
AWS_LOGF_ERROR(

tests/fuzz/fuzz_buffer_pool_special_size.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
8484
/* Get initial stats */
8585
struct aws_s3_default_buffer_pool_usage_stats initial_stats = aws_s3_default_buffer_pool_get_usage(buffer_pool);
8686
size_t primary_cutoff = initial_stats.primary_cutoff;
87+
size_t primary_min_cutoff = initial_stats.primary_min_cutoff;
8788

8889
/* Add special sizes - consume as much input as available */
8990
size_t special_sizes[MAX_SPECIAL_SIZES] = {0};
@@ -179,7 +180,11 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
179180
} else if (size_type == 1) {
180181
/* Primary storage allocation (below primary_cutoff) */
181182
reservation_size = 1024 + (size_value % (primary_cutoff - 1024));
182-
is_primary = true;
183+
if (reservation_size < primary_min_cutoff) {
184+
is_secondary = true;
185+
} else {
186+
is_primary = true;
187+
}
183188
} else {
184189
/* Secondary storage allocation (above primary_cutoff, below smallest special size) */
185190
size_t secondary_range = special_sizes[0] - primary_cutoff - 1;

0 commit comments

Comments
 (0)