From a5d63f9052f0d9d843867edbb3e8287834273e2f Mon Sep 17 00:00:00 2001 From: Xavier Stouder Date: Sat, 11 May 2024 15:27:03 +0200 Subject: [PATCH] buffer: use size_t instead of uint32_t to avoid segmentation fault MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes: https://github.com/nodejs/node/issues/46836 PR-URL: https://github.com/nodejs/node/pull/48033 Reviewed-By: Ben Noordhuis Reviewed-By: Luigi Pinca Reviewed-By: Michaƫl Zasso Reviewed-By: James M Snell Reviewed-By: Minwoo Jung Reviewed-By: Shelley Vohr Reviewed-By: Stephen Belanger --- src/string_bytes.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/string_bytes.cc b/src/string_bytes.cc index c6ebcf89c4058b..6b9d1b41a9fba3 100644 --- a/src/string_bytes.cc +++ b/src/string_bytes.cc @@ -627,11 +627,11 @@ size_t StringBytes::hex_encode( char* dst, size_t dlen) { // We know how much we'll write, just make sure that there's space. - CHECK(dlen >= slen * 2 && - "not enough space provided for hex encode"); + CHECK(dlen >= MultiplyWithOverflowCheck(slen, 2u) && + "not enough space provided for hex encode"); dlen = slen * 2; - for (uint32_t i = 0, k = 0; k < dlen; i += 1, k += 2) { + for (size_t i = 0, k = 0; k < dlen; i += 1, k += 2) { static const char hex[] = "0123456789abcdef"; uint8_t val = static_cast(src[i]); dst[k + 0] = hex[val >> 4];