Skip to content

Commit 19fe5dc

Browse files
committed
Ensure sizes stay within limits of embedded encoder
Really well-spotted by @jbachorik .
1 parent d3fd5b3 commit 19fe5dc

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

ddprof-lib/src/main/cpp/otel_process_ctx.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -465,11 +465,17 @@ static otel_process_ctx_result otel_process_ctx_encode_protobuf_payload(char **o
465465
size_t array_value_content_size = protobuf_otel_array_value_content_size(data.thread_ctx_config->attribute_key_map);
466466
size_t any_value_content_size = protobuf_record_size(array_value_content_size);
467467
size_t kv_content_size = protobuf_string_size("threadlocal.attribute_key_map") + protobuf_record_size(any_value_content_size);
468+
if (kv_content_size > UINT14_MAX) {
469+
return (otel_process_ctx_result) {.success = false, .error_message = "Encoded size of attribute_key_map exceeds UINT14_MAX limit (" __FILE__ ":" ADD_QUOTES(__LINE__) ")"};
470+
}
468471
thread_ctx_pairs_size += protobuf_record_size(kv_content_size);
469472
}
470473
}
471474

472475
size_t resource_size = pairs_size + resource_attributes_pairs_size;
476+
if (resource_size > UINT14_MAX) {
477+
return (otel_process_ctx_result) {.success = false, .error_message = "Encoded size of resource attributes exceeds UINT14_MAX limit (" __FILE__ ":" ADD_QUOTES(__LINE__) ")"};
478+
}
473479
size_t total_size = protobuf_record_size(resource_size) + extra_attributes_pairs_size + thread_ctx_pairs_size;
474480

475481
char *encoded = (char *) calloc(total_size, 1);

0 commit comments

Comments
 (0)