Skip to content

fix: set transform parameters by value when reconstructing from JSON - #1581

Merged
thewtex merged 1 commit into
InsightSoftwareConsortium:mainfrom
vboussot:fix/bspline-transform-reconstruction
Aug 7, 2026
Merged

fix: set transform parameters by value when reconstructing from JSON#1581
thewtex merged 1 commit into
InsightSoftwareConsortium:mainfrom
vboussot:fix/bspline-transform-reconstruction

Conversation

@vboussot

@vboussot vboussot commented Aug 6, 2026

Copy link
Copy Markdown
Collaborator

CopyInFixedParameters/CopyInParameters std::copy into the transform's existing m_FixedParameters/m_Parameters without resizing them; the base class documents the requirement as "the range of values must conform to std::copy(begin, end, m_Parameters)". That holds for transforms that size those members in their constructor, but not for itk::BSplineTransform: its parameter count is unknown until the grid is set, and it keeps its coefficients in its own m_InternalParametersBuffer, so the base m_Parameters stays empty. Copying into it runs off the end of a zero-length buffer, which segfaults natively and aborts the module with no diagnostic under WebAssembly.

Use SetFixedParameters and SetParametersByValue instead, which every transform implements as a copy, and check the parameter count so a mismatch reports instead of corrupting memory. Fixed parameters are set first: for a B-spline they define the grid, and hence the number of parameters.

Fixed in both places that reconstruct a transform from TransformListJSON: itkWasmTransformToTransformFilter, in its composite and non-composite branches, and the copy of that pattern in the downsample package's resample pipelines.

Adds itkWasmTransformInterfaceBSplineTest, which round-trips a composite containing a B-spline through the interface. No existing test exercised a B-spline on this path, which is why the defect went unnoticed; the new test segfaults without this change.

Closes #1580

CopyInFixedParameters/CopyInParameters std::copy into the transform's existing
m_FixedParameters/m_Parameters without resizing them; the base class documents
the requirement as "the range of values must conform to
std::copy(begin, end, m_Parameters)". That holds for transforms that size those
members in their constructor, but not for itk::BSplineTransform: its parameter
count is unknown until the grid is set, and it keeps its coefficients in its own
m_InternalParametersBuffer, so the base m_Parameters stays empty. Copying into
it runs off the end of a zero-length buffer, which segfaults natively and aborts
the module with no diagnostic under WebAssembly.

Use SetFixedParameters and SetParametersByValue instead, which every transform
implements as a copy, and check the parameter count so a mismatch reports
instead of corrupting memory. Fixed parameters are set first: for a B-spline
they define the grid, and hence the number of parameters.

Fixed in both places that reconstruct a transform from TransformListJSON:
itkWasmTransformToTransformFilter, in its composite and non-composite branches,
and the copy of that pattern in the downsample package's resample pipelines.

Adds itkWasmTransformInterfaceBSplineTest, which round-trips a composite
containing a B-spline through the interface. No existing test exercised a
B-spline on this path, which is why the defect went unnoticed; the new test
segfaults without this change.

Closes InsightSoftwareConsortium#1580

@thewtex thewtex left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🥇

@thewtex

thewtex commented Aug 7, 2026

Copy link
Copy Markdown
Member

@vboussot thank you!

Since we changed the ITKWebAssemblyInterface module, we will need to first release a new docker base image, then release the downsample package built against this image. I will merge this after CI for the toolchain docker base images finishes green, then follow-up with those steps.

@thewtex
thewtex merged commit f8e99da into InsightSoftwareConsortium:main Aug 7, 2026
60 of 87 checks passed
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.

resample-bounding-box aborts in WebAssembly for any BSplineTransform

2 participants