@@ -457,23 +457,26 @@ void executeActions(const test::common::buffer::BufferFuzzTestCase& input, Buffe
457
457
// return the pointer to its std::string array, we can avoid the
458
458
// toString() copy here.
459
459
const uint64_t linear_buffer_length = linear_buffers[j]->length ();
460
- if (buffers[j]->toString () !=
461
- absl::string_view (
460
+ // We may have spilled over TotalMaxAllocation at this point. Only compare up to
461
+ // TotalMaxAllocation.
462
+ if (absl::string_view (
462
463
static_cast <const char *>(linear_buffers[j]->linearize (linear_buffer_length)),
463
- linear_buffer_length)) {
464
+ linear_buffer_length)
465
+ .compare (buffers[j]->toString ().substr (0 , TotalMaxAllocation)) != 0 ) {
464
466
ENVOY_LOG_MISC (debug, " Mismatched buffers at index {}" , j);
465
467
ENVOY_LOG_MISC (debug, " B: {}" , buffers[j]->toString ());
466
468
ENVOY_LOG_MISC (debug, " L: {}" , linear_buffers[j]->toString ());
467
469
FUZZ_ASSERT (false );
468
470
}
469
- FUZZ_ASSERT (buffers[j]->length () == linear_buffer_length);
471
+ FUZZ_ASSERT (std::min (TotalMaxAllocation, static_cast <uint32_t >(buffers[j]->length ())) ==
472
+ linear_buffer_length);
470
473
current_allocated_bytes += linear_buffer_length;
471
474
}
472
475
ENVOY_LOG_MISC (debug, " [{} MB allocated total]" , current_allocated_bytes / (1024.0 * 1024 ));
473
476
// We bail out if buffers get too big, otherwise we will OOM the sanitizer.
474
477
// We can't use Memory::Stats::totalCurrentlyAllocated() here as we don't
475
478
// have tcmalloc in ASAN builds, so just do a simple count.
476
- if (current_allocated_bytes > TotalMaxAllocation) {
479
+ if (current_allocated_bytes >= TotalMaxAllocation) {
477
480
ENVOY_LOG_MISC (debug, " Terminating early with total buffer length {} to avoid OOM" ,
478
481
current_allocated_bytes);
479
482
break ;
0 commit comments