fix: convert ccall pointer returns to unsigned in run-pipeline-emscriten#1503
Merged
thewtex merged 1 commit intoInsightSoftwareConsortium:mainfrom Apr 9, 2026
Merged
Conversation
…pten Emscripten's ccall returns WASM pointers as signed i32. When the heap exceeds 2 GB, pointers above 2^31 wrap negative, causing: RangeError: Start offset -N is outside the bounds of the buffer Apply >>> 0 to all 7 ccall sites that return pointers (4 helper functions + 3 inline output readers) so they are treated as unsigned. Adds a regression test that reuses an Emscripten module across two large-image pipeline calls, reproducing the real-world scenario of a persistent web worker whose heap accumulates past 2 GB.
thewtex
approved these changes
Apr 9, 2026
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.
Fix signed pointer overflow in
runPipelineEmscriptenwhen WASM heap exceeds 2 GB. Apply>>> 0to all 7ccallsites returning pointers. Add regression test.Problem
Emscripten's
ccallreturns pointers as signed i32. When a module is reused (web worker pattern) and the heap exceeds 2 GB, pointers above 2^31 wrap negative:Reported via VolView issue loading a 1024x1024x172 Float32 image + NIfTI labelmap on the same worker.
Fix
>>> 0is a no-op for pointers below 2^31, so safe for all heap sizes.Emscripten precedent
The Emscripten settings reference states: "If the maximum heap size is over 2GB, then pointers must be unsigned in JavaScript." The same bug class was fixed in Emscripten's own
library_webgl.js(#20137) and pointer types were changed to unsigned forCAN_ADDRESS_2GBmode (#21278).