From: Mika Lindqvist Date: Fri, 16 May 2025 22:10:28 +0000 (+0300) Subject: [WebAssembly] Fix stack overflow in crc32_chorba_118960_nondestructive. X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f90c01107f101f570047cb885e07f3be5904c1a7;p=thirdparty%2Fzlib-ng.git [WebAssembly] Fix stack overflow in crc32_chorba_118960_nondestructive. --- diff --git a/arch/generic/crc32_chorba_c.c b/arch/generic/crc32_chorba_c.c index 604e39f8..036bfc58 100644 --- a/arch/generic/crc32_chorba_c.c +++ b/arch/generic/crc32_chorba_c.c @@ -1,4 +1,7 @@ #include "zbuild.h" +#if defined(__EMSCRIPTEN__) +# include "zutil_p.h" +#endif #include "crc32_braid_p.h" #include "crc32_braid_tbl.h" #include "generic_functions.h" @@ -25,7 +28,11 @@ * @note Uses 128KB temporary buffer */ Z_INTERNAL uint32_t crc32_chorba_118960_nondestructive (uint32_t crc, const z_word_t* input, size_t len) { +#if defined(__EMSCRIPTEN__) + z_word_t* bitbuffer = (z_word_t*)zng_alloc(bitbuffersizebytes); +#else ALIGNED_(16) z_word_t bitbuffer[bitbuffersizezwords]; +#endif const uint8_t* bitbufferbytes = (const uint8_t*) bitbuffer; size_t i = 0; @@ -480,6 +487,9 @@ Z_INTERNAL uint32_t crc32_chorba_118960_nondestructive (uint32_t crc, const z_wo crc = crc_table[(crc ^ final_bytes[j] ^ bitbufferbytes[(j+i) % bitbuffersizebytes]) & 0xff] ^ (crc >> 8); } +#if defined(__EMSCRIPTEN__) + zng_free(bitbuffer); +#endif return crc; }