From 73b648c70448d017945f1ce6ab2fe03a9c3a63a0 Mon Sep 17 00:00:00 2001 From: Richard Geldreich Date: Fri, 23 Oct 2026 18:08:46 -0400 Subject: [PATCH] containers: increase_capacity() returns false before asserting when nofail_flag is set try_resize()/try_reserve() etc. (nofail) are used to fail cleanly on huge allocations, e.g. the Wuffs LDR loader's pixel and work buffers for a small crafted file whose header claims a big image. In Debug the assert(0) fired before the nofail check, so such a file aborted Debug builds instead of failing the load. Callers without nofail are unchanged (assert, then abort). Co-Authored-By: Claude Opus 5.5 --- transcoder/basisu_containers_impl.h | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/transcoder/basisu_containers_impl.h b/transcoder/basisu_containers_impl.h index b66efc9..aafb751 100644 --- a/transcoder/basisu_containers_impl.h +++ b/transcoder/basisu_containers_impl.h @@ -47,10 +47,10 @@ namespace basisu // Basic sanity check min_new_capacity if (!can_fit_into_size_t((uint64_t)min_new_capacity * element_size)) { - assert(0); - if (nofail_flag) return false; + + assert(0); container_abort("elemental_vector::increase_capacity: requesting too many elements\n"); } @@ -79,11 +79,11 @@ namespace basisu if (!can_fit_into_size_t(new_capacity_u64)) { - assert(0); - if (nofail_flag) return false; + assert(0); + container_abort("elemental_vector::increase_capacity: vector too large\n"); } } @@ -92,11 +92,11 @@ namespace basisu if (!can_fit_into_size_t(desired_size_u64)) { - assert(0); - if (nofail_flag) return false; + assert(0); + container_abort("elemental_vector::increase_capacity: vector too large\n"); } @@ -111,11 +111,11 @@ namespace basisu if (!new_p) { fprintf(stderr, "elemental_vector::increase_capacity: Allocation failed!\n"); - assert(0); - if (nofail_flag) return false; + assert(0); + container_abort("elemental_vector::increase_capacity: realloc() failed allocating %zu bytes", desired_size); } @@ -136,11 +136,11 @@ namespace basisu if (!new_p) { fprintf(stderr, "elemental_vector::increase_capacity: Allocation failed!\n"); - assert(0); - if (nofail_flag) return false; + assert(0); + container_abort("elemental_vector::increase_capacity: malloc() failed allocating %zu bytes", desired_size); }