]> git.ipfire.org Git - thirdparty/zlib-ng.git/commitdiff
[WebAssembly] Fix stack overflow in crc32_chorba_118960_nondestructive.
authorMika Lindqvist <postmaster@raasu.org>
Fri, 16 May 2025 22:10:28 +0000 (01:10 +0300)
committerHans Kristian Rosbach <hk-github@circlestorm.org>
Tue, 27 May 2025 12:45:52 +0000 (14:45 +0200)
arch/generic/crc32_chorba_c.c

index 604e39f8382cfdaba25677ba0f196b97d22890d2..036bfc58c8c43e47e6a7ca7649bbffa74195680f 100644 (file)
@@ -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"
  * @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;
 }