Repository navigation
Validate idxs/out in in-place interpolation entry points - #4607
Merged
ChrisRackauckas merged 7 commits intoSep 27, 2026
Merged
Conversation
In-place dense interpolation reached per-algorithm _ode_interpolant! kernels that index out/y₀ under @inbounds with no up-front validation, so sol(out, t; idxs) silently wrote past the end of out or read out-of-bounds state. Check idxs against the state and out length once at the OrdinaryDiffEqCore entry points. Co-Authored-By: Chris Rackauckas <[email protected]> Co-Authored-By: Devin <[email protected]> Agent-Harness: devin 3000.11.1 (cc4e349ca55e) Agent-Model: swe-2-high Agent-Session: local Devin session in /home/crackauc/sandbox/goals/performance/jobs/OrdinaryDiffEqTsit5/repo (log: /home/crackauc/sandbox/goals/performance/jobs/OrdinaryDiffEqTsit5/log.txt)
Review fixes: the vector-of-times entry point validated only vals[1], letting mixed-length output containers slip through to the @inbounds kernels. Validate each element up front, keep the throw in a @noinline helper, drop the inaccurate SAFETY comment in OrdinaryDiffEqTsit5, and extend the testset to the integrator path and mixed-length outs. Co-Authored-By: Chris Rackauckas <[email protected]> Co-Authored-By: Devin <[email protected]> Agent-Harness: devin 3000.11.1 (cc4e349ca55e) Agent-Model: swe-2-high Agent-Session: local Devin session in /home/crackauc/sandbox/goals/performance/jobs/OrdinaryDiffEqTsit5/repo (log: /home/crackauc/sandbox/goals/performance/jobs/OrdinaryDiffEqTsit5/log.txt)
eachindex on an AbstractVectorOfArray yields CartesianIndices over all elements while _get_val reads vals.u[i], so in-place interpolation into a VectorOfArray threw BoundsError. Add _vals_indices overloads matching the _get_val/_set_val! pattern, hoist the state checkbounds out of the per-element loop, and cover VectorOfArray outputs in the testset. Co-Authored-By: Chris Rackauckas <[email protected]> Co-Authored-By: Devin <[email protected]> Agent-Harness: devin 3000.11.1 (cc4e349ca55e) Agent-Model: swe-2-high Agent-Session: local Devin session in /home/crackauc/sandbox/goals/performance/jobs/OrdinaryDiffEqTsit5/repo (log: /home/crackauc/sandbox/goals/performance/jobs/OrdinaryDiffEqTsit5/log.txt)
The guard checked timeseries[1], so callback-resized solutions were rejected post-grow and passed unchecked post-shrink. Check both timeseries[i₋] and timeseries[i₊] after the interval is chosen (kernels variously index y₀ or y₁ under idxs), per requested time in the vector-of-times path, and integrator.uprev alongside integrator.u. Co-Authored-By: Chris Rackauckas <[email protected]> Co-Authored-By: Devin <[email protected]> Agent-Harness: devin 3000.11.1 (cc4e349ca55e) Agent-Model: swe-2-high Agent-Session: local Devin session in /home/crackauc/sandbox/goals/performance/jobs/OrdinaryDiffEqTsit5/repo (log: /home/crackauc/sandbox/goals/performance/jobs/OrdinaryDiffEqTsit5/log.txt)
Logical masks select count(mask) components, so compare `out` against count(idxs) for Bool-eltype selectors and let checkbounds do the logical-index bounds check. In the vector-of-times loop, skip the selector rescan while consecutive interval states keep the axes already validated. Co-Authored-By: Chris Rackauckas <[email protected]> Co-Authored-By: Devin <[email protected]> Agent-Harness: devin 3000.11.1 (cc4e349ca55e) Agent-Model: swe-2-high Agent-Session: local Devin session in /home/crackauc/sandbox/goals/performance/jobs/OrdinaryDiffEqTsit5/repo (log: /home/crackauc/sandbox/goals/performance/jobs/OrdinaryDiffEqTsit5/log.txt)
The up-front per-output length preflight read every vals slot
whenever idxs !== nothing, so valid uninitialized Vector{Any}/
Vector{BigFloat} buffers on the _set_val! path threw UndefRefError.
Skip slot reads unless the vals elements are arrays; the per-time
idxs/state check already never touches slots.
Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Devin <[email protected]>
Agent-Harness: devin 3000.11.1 (cc4e349ca55e)
Agent-Model: swe-2-high
Agent-Session: local Devin session in /home/crackauc/sandbox/goals/performance/jobs/OrdinaryDiffEqTsit5/repo (log: /home/crackauc/sandbox/goals/performance/jobs/OrdinaryDiffEqTsit5/log.txt)
SciMLBase does not require length(vals) == length(tvals); the main loop only writes eachindex(tvals) slots, so an over-long buffer with untouched extra slots must not be inspected — an uninitialized extra slot threw UndefRefError and a wrong-length extra slot threw DimensionMismatch, both accepted on master. Co-Authored-By: Chris Rackauckas <[email protected]> Co-Authored-By: Devin <[email protected]> Agent-Harness: devin 3000.11.1 (cc4e349ca55e) Agent-Model: swe-2-high Agent-Session: local Devin session in /home/crackauc/sandbox/goals/performance/jobs/OrdinaryDiffEqTsit5/repo (log: /home/crackauc/sandbox/goals/performance/jobs/OrdinaryDiffEqTsit5/log.txt)
ChrisRackauckas-Claude
pushed a commit
to ChrisRackauckas-Claude/OrdinaryDiffEq.jl
that referenced
this pull request
Sep 27, 2026
Mirror SciML#4607's eachindex(tvals) over-long buffer coverage for the idxs===nothing path: extra uninitialized or wrong-length slots beyond the written range must remain untouched, matching master. Co-Authored-By: Chris Rackauckas <[email protected]> Co-Authored-By: Cursor Agent <[email protected]> Agent-Harness: Cursor Agent 2026.09.26-dd393fe Agent-Model: auto Agent-Session: local cursor-agent session in /home/crackauc/sandbox/goals/performance/jobs/pr-out-size/repo (log /home/crackauc/sandbox/goals/performance/jobs/pr-out-size/log6.txt)
ChrisRackauckas
marked this pull request as ready for review
September 27, 2026 14:43
ChrisRackauckas
added a commit
to ChrisRackauckas-Claude/OrdinaryDiffEq.jl
that referenced
this pull request
Sep 27, 2026
Mirror SciML#4607's eachindex(tvals) over-long buffer coverage for the idxs===nothing path: extra uninitialized or wrong-length slots beyond the written range must remain untouched, matching master. Co-Authored-By: Chris Rackauckas <[email protected]> Co-Authored-By: Cursor Agent <[email protected]> Agent-Harness: Cursor Agent 2026.09.26-dd393fe Agent-Model: auto Agent-Session: local cursor-agent session in /home/crackauc/sandbox/goals/performance/jobs/pr-out-size/repo (log /home/crackauc/sandbox/goals/performance/jobs/pr-out-size/log6.txt)
ChrisRackauckas
added a commit
that referenced
this pull request
Sep 27, 2026
* Reject wrong-length out for idxs=nothing interpolation With idxs === nothing the in-place dense kernels loop over out under @inbounds with no length check against the state, so a short out silently truncates and a long out OOB-reads state. Require length(out) == length(u) against the interpolated interval's states (timeseries[i₋]/[i₊], integrator.uprev/u), per requested time in the vector path — not timeseries[1], which breaks after callback resize!. Co-Authored-By: Chris Rackauckas <[email protected]> Co-Authored-By: Cursor Agent <[email protected]> Agent-Harness: Cursor Agent 2026.09.26-dd393fe Agent-Model: auto Agent-Session: local cursor-agent session in /home/crackauc/sandbox/goals/performance/jobs/pr-out-size/repo (log /home/crackauc/sandbox/goals/performance/jobs/pr-out-size/log.txt) * Avoid reading uninitialized scalar batch interp outs The idxs===nothing length guard read vals[j] before choosing the mutate-in-place vs replace-slot path, so Vector{Any}/BigFloat(undef) buffers that only need _set_val! threw UndefRefError. Read and length- check only on AbstractArray element paths; validate idxs vs state without reading the slot on the replace path. Co-Authored-By: Chris Rackauckas <[email protected]> Co-Authored-By: Cursor Agent <[email protected]> Agent-Harness: Cursor Agent 2026.09.26-dd393fe Agent-Model: auto Agent-Session: local cursor-agent session in /home/crackauc/sandbox/goals/performance/jobs/pr-out-size/repo (log /home/crackauc/sandbox/goals/performance/jobs/pr-out-size/log.txt) * Assert over-long outs ok for idxs=nothing vector interp Mirror #4607's eachindex(tvals) over-long buffer coverage for the idxs===nothing path: extra uninitialized or wrong-length slots beyond the written range must remain untouched, matching master. Co-Authored-By: Chris Rackauckas <[email protected]> Co-Authored-By: Cursor Agent <[email protected]> Agent-Harness: Cursor Agent 2026.09.26-dd393fe Agent-Model: auto Agent-Session: local cursor-agent session in /home/crackauc/sandbox/goals/performance/jobs/pr-out-size/repo (log /home/crackauc/sandbox/goals/performance/jobs/pr-out-size/log6.txt) --------- Co-authored-by: ChrisRackauckas-Claude <[email protected]> Co-authored-by: Cursor Agent <[email protected]>
ChrisRackauckas
referenced
this pull request
Sep 29, 2026
* Bump DiffEqBase to 7.21.3 Co-Authored-By: Chris Rackauckas <[email protected]> Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com> Agent-Harness: Devin CLI 3000.11.3 (Mac) Agent-Model: Fusion (claude-opus-5-5 medium + swe-2 medium) Agent-Session: local transcript ~/.local/share/devin/cli/transcripts/helpful-exception.json * Bump OrdinaryDiffEqBDF to 2.4.12 Co-Authored-By: Chris Rackauckas <[email protected]> Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com> Agent-Harness: Devin CLI 3000.11.3 (Mac) Agent-Model: Fusion (claude-opus-5-5 medium + swe-2 medium) Agent-Session: local transcript ~/.local/share/devin/cli/transcripts/helpful-exception.json * Bump OrdinaryDiffEqSDIRK to 2.9.7 Co-Authored-By: Chris Rackauckas <[email protected]> Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com> Agent-Harness: Devin CLI 3000.11.3 (Mac) Agent-Model: Fusion (claude-opus-5-5 medium + swe-2 medium) Agent-Session: local transcript ~/.local/share/devin/cli/transcripts/helpful-exception.json * Bump OrdinaryDiffEqRosenbrock to 2.7.5 Co-Authored-By: Chris Rackauckas <[email protected]> Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com> Agent-Harness: Devin CLI 3000.11.3 (Mac) Agent-Model: Fusion (claude-opus-5-5 medium + swe-2 medium) Agent-Session: local transcript ~/.local/share/devin/cli/transcripts/helpful-exception.json * Bump OrdinaryDiffEqLowOrderRK to 2.2.6 Co-Authored-By: Chris Rackauckas <[email protected]> Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com> Agent-Harness: Devin CLI 3000.11.3 (Mac) Agent-Model: Fusion (claude-opus-5-5 medium + swe-2 medium) Agent-Session: local transcript ~/.local/share/devin/cli/transcripts/helpful-exception.json * Bump OrdinaryDiffEqTsit5 to 2.1.5 Co-Authored-By: Chris Rackauckas <[email protected]> Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com> Agent-Harness: Devin CLI 3000.11.3 (Mac) Agent-Model: Fusion (claude-opus-5-5 medium + swe-2 medium) Agent-Session: local transcript ~/.local/share/devin/cli/transcripts/helpful-exception.json * Bump OrdinaryDiffEqVerner to 2.4.2 Co-Authored-By: Chris Rackauckas <[email protected]> Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com> Agent-Harness: Devin CLI 3000.11.3 (Mac) Agent-Model: Fusion (claude-opus-5-5 medium + swe-2 medium) Agent-Session: local transcript ~/.local/share/devin/cli/transcripts/helpful-exception.json * Bump OrdinaryDiffEqSymplecticRK to 2.2.3 Co-Authored-By: Chris Rackauckas <[email protected]> Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com> Agent-Harness: Devin CLI 3000.11.3 (Mac) Agent-Model: Fusion (claude-opus-5-5 medium + swe-2 medium) Agent-Session: local transcript ~/.local/share/devin/cli/transcripts/helpful-exception.json --------- Co-authored-by: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
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.
What changed and why
In-place dense/continuous interpolation (
sol(out, t; idxs), vector-of-timessol(outs, ts; idxs), and the integrator-pathode_interpolant!/ode_extrapolant!) reached per-algorithm_ode_interpolant!kernels that indexout/y₀/y₁/kunder@inboundswith no up-front validation.sol(zeros(2), 0.5; idxs=1:3)on a 3-state problem silently wrote past the end ofout— under default bounds the test suite does not just fail, it segfaults Julia in GC marking (signal 11, heap corrupted by the OOB write).This PR adds a guard at the OrdinaryDiffEqCore entry points:
checkboundson the state the kernel will actually read, andDimensionMismatchwhenout's length differs from the number of selected components (length(idxs)for integer vectors,count(idxs)forBoolmasks —Bool <: Integer, but a logical mask selectscount(mask)components). Crucially the state check validates against the interval being interpolated —timeseries[i₋]andtimeseries[i₊]are both checked (per-algorithm kernels variously indexy₀ory₁underidxs; e.g. BDF readsy₁[idxs], Rosenbrock Hermite reads both), and the check runs afteri₋/i₊are chosen, so solutions whose state is resized by a callback validate correctly on either side of the resize. The vector-of-times path validates per requested time inside the loop, skipping the rescan while consecutive interval states keep the axes already validated, and checks every output element's length up front via_vals_indices(eachindex(vals.u)forAbstractVectorOfArray), so mixed-lengthoutsare rejected. The integrator path checksintegrator.uprevandintegrator.u. TheDimensionMismatchconstruction lives in a small@noinlinehelper so the inlined guard stays cheap; the guard compiles out foridxs === nothing.Verification
Testset
interpolation_idxs_bounds_tests.jl(51 assertions in four sets) covers scalar-time, vector-of-times, mixed-lengthouts,VectorOfArrayoutputs,Vector{Bool}/BitVectormasks (dense=false, scalar and vector times, valid and wrong-lengthout), uninitializedVector{Any}/Vector{BigFloat}output buffers (replace-slot path;idxs=1/[1],Val{0}/Val{1}), the integrator path, and grow/shrink callback resizes (valid and invalididxs, bothcontinuitysides at the resize time, per-time interval validation).On master source, under
--check-bounds=yes(thePkg.testdefault, i.e. what CI runs):The 4 failures are the
DimensionMismatchassertions — each throwsBoundsErrorinstead on master, so they discriminate in CI. TheBoundsErrorassertions already pass on master under--check-bounds=yes(bounds checking overrides@inbounds); they only discriminate under--check-bounds=auto, where on master no exception is thrown — and in fact the run does not get that far:The mask assertions pass on master (10/10 standalone, matching
mask-regression.jlresults of 4/4) and errored at1a69f7740—sol(zeros(2), 0.5; idxs=[true,false,true])threwDimensionMismatch: out has length 2 but idxs has length 3— and pass after the fix.An earlier version of this guard validated against
timeseries[1](the initial state). That broke interpolation of solutions resized by callbacks: at67ab757the grow case fails under both bounds modes —With this fix the full file passes under both modes:
At
45804a031theuninitialized outsset errors withUndefRefError(the slot preflight read#undefelements); the identical calls succeed on master (Vector{Any}/BigFloatundef buffers) and pass after the fix. ForBigFloat+ vectoridxsthe stored value is aVector{Float64}, so slot assignment is aMethodError— identical on master.At
5fcf6165cthe preflight looped over everyvalsslot, but the main loop only writeseachindex(tvals)slots andvalsmay be longer thantvals: an over-long buffer with an uninitialized extra slot threwUndefRefError, and one with a wrong-length extra slot threwDimensionMismatch— both accepted on master. Fixed by iteratingeachindex(tvals); regression tests cover both over-long cases.The reviewer's 576-case output-read audit (
idxs-audit.jl: Float64/BigFloat × Array/ArrayPartition × dense/linear × Val{0}/Val{1} × scalar/vector/Bool idxs × undef/over-long/VoA/integrator/extrapolant outputs) is identical between master and this head on every case (390/576 OK — the rest error identically on both).The resize assertions were verified to match the allocating path exactly:
idxs=[3]att=0.5throwsBoundsErrorundercontinuity=:leftfor a 2→3 grow (pre-resize state, len 2) and works under:right(post-resize, len 3, value2.0); symmetric for a 3→2 shrink (:leftreturns the pre-shrink value,:rightthrows).Relevant test group —
GROUP=Corefor OrdinaryDiffEqCore (defaultPkg.testsettings):Runic
--checkon all changed files: exit 0.typosover the diff: exit 0.Before/after numbers
In-place interpolation of a
Tsit5solution over 1000 time points,@benchmarkmedians, 3 trials per run, pinned (JULIA_NUM_THREADS=1 taskset -c <core>,--check-bounds=auto), same protocol as the reviewer'sperf-focused.jl. Median-of-trial-medians:n=3, idxs=collect(1:3): prior ~111 μs →1a69f~122 μs (+10%) →45804a0~115/68 μs →5fcf616~113 μsn=256, idxs=collect(1:256): prior ~2.20 ms →1a69f~2.32 ms (+5–9%) →45804a0~1.28/1.30 ms →5fcf616~2.1 msidxs=nothingcontrols unchanged (~0.24–0.33 ms), 8,072 B / 3 allocs in all measured calls. Machine variance is large (two45804a0runs differed ~40% within a config), so the honest statement is: at/around prior medians, not the repeatable +9–10% seen at1a69f.The axes-dedup keeps interval-specific validation while paying one axes-tuple comparison per requested time instead of rescanning the selector; the per-time
checkboundsoverhead measured at1a69fis gone. The undef-buffer fix removes work (the preflight loop no longer runs on the replace path), so it cannot regress the vector-times check.What was not verified
ks[i₊]withidxs; the stage vectors share the interval state's provenance, and no scenario was found where they differ in length from bothtimeseriesendpoints.Bool-maskidxsis only verified fordense=false(linear interpolant). Withdense=truethe allocating path itself rejects masks (ArgumentError: invalid index: true), same as master.valselements are arrays, matching_set_val!-replace-path semantics: uninitializedAny/BigFloatbuffers are never read. For those buffers theout-length check cannot run (there is no meaningfullengthof an undef slot); bounds/idxsvalidation still applies via the per-time state check.ode_interpolant!/ode_extrapolant!overloads (bypassing theDEIntegrator/InterpolationDataentry points) remain unvalidated, as before.Please ignore until reviewed by @ChrisRackauckas.
Risk assessment
sol(out,t;idxs),sol(outs,ts;idxs),integrator(out,t;idxs), extrapolant); guard compiles out foridxs=nothing; only shapes that were memory-unsafe now throw. No public API change. Re-review cycles caught three regressions — aVectorOfArrayiteration bug (eachindexyieldsCartesianIndices), validation againsttimeseries[1]breaking callback-resized solutions, and a false reject ofBool-maskidxs(countvslength) — plus anUndefRefErroron uninitializedVector{Any}/BigFloatoutput buffers on the replace-slot path — all fixed and covered by dedicated tests.--check-bounds=yesthe testset fails 4/12 (DimensionMismatch assertions); under default bounds it segfaults in GC from the OOB write; with the fix 38/38 pass under both bounds modes, including grow/shrink resize cases verified identical to the allocating path,VectorOfArrayoutput verified working on master / broken at 5dcc5e2 / working after,Bool/BitVectormasks verified passing on master / erroring at 1a69f77 / passing after, andVector{Any}/BigFloatundef buffers verified passing on master /UndefRefErrorat 45804a0 / passing after, and over-long output buffers verified on master /UndefRefError+DimensionMismatchat 5fcf616 / passing after (576-case audit identical to master). Vector-of-times perf: +9–10% at 1a69f77 → back to prior medians after the axes dedup.🤖 Generated with Devin (model: swe-2-high), local session, orchestrated by Claude Code (claude-opus-5-5[1m]) session https://claude.ai/code/session_01LPHREnnonfLg1VcE1EJovv
Risk assessment
idxs. Invalid inputs now throw explicit bounds/dimension errors; no valid-input API break requiring a SemVer bump identified. No weakened tests or new non-public dependency access found.9a75ffb9f: 253 successful, 8 failed, 3 skipped checks. All eight failures are pre-existing, with matching errors in recent default-branch logs: SciMLSensitivity Core1—MooncakeAnyconstructor (master); downgrade DiffEqBase—callback assertions, and downgrade OrdinaryDiffEqDifferentiation—diag(ScalarOperator)(master); DelayDiffEq Regression—Waltman NaNs, GlobalDiffEq Core—callback rejection, OrdinaryDiffEqDifferentiation Core—diag(ScalarOperator), and OrdinaryDiffEqNonlinearSolve Core—Trapezoid mass-matrix rejection (master); root GPU Julia 1—QNDF CSC/diagonal-CuArray mismatch (master). Core tests, QA, GPU, documentation, and formatting pass. No review comments exist._vals_indicesdescribed as active, and stale 38/38 versus 51/51 assertion count).🤖 Risk assessment posted by an AI agent (fleet master) — harness: Codex CLI 0.156.1 (Mac) / gpt-6-astra; dispatched by Claude Code head, model claude-opus-5-5[1m]
Conversation: local Claude Code session 3cd6500a-1f81-46b5-ac0b-c466e15b6a53 on Chris's Mac (session ID, no URL)