fix: WASM crash in cloudsync_set_column on tables with existing rows#42
Merged
fix: WASM crash in cloudsync_set_column on tables with existing rows#42
Conversation
cloudsync_memory_alloc (dbmem_alloc, uint64_t) was cast directly into fractional_indexing_allocator.malloc (void *(*)(size_t)). Native size_t is 64-bit so the cast is a no-op, but WASM size_t is 32-bit and call_indirect enforces strict typing: the function is registered as (i64)->i32 and called as (i32)->i32, crashing cloudsync_set_column on a table with pre-existing rows during the block-index migration. Bridge via fi_malloc_wrapper, matching the existing fi_calloc_wrapper pattern.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Calling cloudsync_set_column(table, col, 'algo', 'block') on a table with pre-existing rows crashes the WASM build with RuntimeError: function signature mismatch as soon as the block-index
migration tries to allocate memory. Native builds are unaffected.
Root cause
src/block.c:137 cast cloudsync_memory_alloc directly into the fractional-indexing allocator slot:
.malloc = (void ()(size_t))cloudsync_memory_alloc,
On native platforms size_t is 64-bit, so the cast is a no-op. In WASM size_t is 32-bit, and call_indirect enforces strict type checking: the function is registered in the table as (i64) -> i32 but
called as (i32) -> i32 — immediate runtime error. Documented Emscripten pitfall: https://emscripten.org/docs/porting/guidelines/function_pointer_issues.html
Fix
Bridge through a thin fi_malloc_wrapper, mirroring the existing fi_calloc_wrapper pattern already used for the calloc slot. free is already fine (dbmem_free(void*) matches the expected signature
on every target).
Changes
Test plan