Skip to content

Fix RangeErrors with large images#856

Merged
PaulHax merged 2 commits intomainfrom
range-fix
Apr 16, 2026
Merged

Fix RangeErrors with large images#856
PaulHax merged 2 commits intomainfrom
range-fix

Conversation

@PaulHax
Copy link
Copy Markdown
Collaborator

@PaulHax PaulHax commented Mar 27, 2026

Fixes two failures when working with large labelmaps:

  • Import (loading a session): bumps itk-wasm to ^1.0.0-b.197 and @itk-wasm/image-io to 1.6.1. The upstream release fixes a signed-pointer overflow in Emscripten
    ccall that raised RangeError: Start offset -N is outside the bounds of the buffer when reading an embedded .nii.gz labelmap from a session whose base image had already
    grown the shared worker's WASM heap past 2GB.

  • Export (saving a session): works around a VTK.js OOM. vtkDataArray.getState() calls Array.from() on the underlying typed array, which OOMs for labelmaps larger
    than ~180M voxels. Added a helper in src/io/vtk/async.ts that temporarily swaps each array's data with an empty buffer before getState(), then re-attaches the original
    TypedArrays to the serialized state so postMessage's structured clone handles them efficiently. Upstream fix in flight at
    Kitware/vtk-js#3472 — once released, this workaround can be removed.

Also surfaces save errors in the UI instead of failing silently.

Closes #852

@PaulHax PaulHax closed this Apr 5, 2026
@PaulHax PaulHax reopened this Apr 5, 2026
@PaulHax PaulHax marked this pull request as ready for review April 5, 2026 18:18
@PaulHax PaulHax requested a review from arhowe00 April 5, 2026 18:33
Base automatically changed from bug-report to main April 16, 2026 17:57
VTK.js DataArray.getState() calls Array.from() on typed arrays, which
OOMs for labelmaps larger than ~180M voxels. Swap each array's data
with empty before getState(), then inject the original TypedArrays
into the serialized state so structured clone (postMessage) handles
them efficiently.

Upstream fix in progress: Kitware/vtk-js#3472 —
once that lands and is released, this workaround can be removed.

Also surface save errors in the UI so they are visible to the user
instead of silently failing.
@netlify
Copy link
Copy Markdown

netlify bot commented Apr 16, 2026

Deploy Preview for volview-dev ready!

Name Link
🔨 Latest commit d53ed45
🔍 Latest deploy log https://app.netlify.com/projects/volview-dev/deploys/69e136b4e4cd980008dfa212
😎 Deploy Preview https://deploy-preview-856--volview-dev.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

Bump itk-wasm to ^1.0.0-b.197 and @itk-wasm/image-io to 1.6.1. The
upstream update fixes a signed-pointer overflow in Emscripten ccall
that triggered a RangeError when reading an embedded .nii.gz labelmap
from a session zip whose base image had already grown the shared
worker's WASM heap past 2GB.

Also drop the control-character sanitize patch for itk-wasm's JSON
output. The upstream fix in InsightSoftwareConsortium/ITK-Wasm#1457
sanitizes invalid UTF-8 and control characters in metadata at the C++
source, so the JS-side workaround is no longer needed. Verified with
the corrupt_dates.dcm fixture from ITK-Wasm#1454 — loads without
JSON.parse errors using the plain b.197 build.

closes #852
@PaulHax PaulHax added this pull request to the merge queue Apr 16, 2026
Merged via the queue into main with commit b02cd52 Apr 16, 2026
7 checks passed
@PaulHax PaulHax deleted the range-fix branch April 16, 2026 19:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

RangeErrors with large images

1 participant