Skip to content

Bounds-check ChainedVector indexing with index vectors and ranges - #130

Merged
quinnj merged 2 commits into
mainfrom
claude/chained-getindex-bounds
Oct 27, 2026
Merged

quinnj merged 2 commits into
mainfrom
claude/chained-getindex-bounds

Conversation

@quinnj

@quinnj quinnj commented Oct 15, 2026 •

Copy link
Copy Markdown
Member

Indexing a ChainedVector with an index vector never checked bounds, so a bad index read arbitrary memory instead of throwing:

julia> x = ChainedVector([[1, 2], [3]]);

julia> x[[1, 4]]
2-element Vector{Int64}:
     1
 38662          # garbage

julia> x[[0]]   # or x[[-1]]
signal 11: Segmentation fault

This happens without @inbounds. The UnitRange method also read before the first chunk for ranges starting below 1, though it then threw a BoundsError from a later checked access.

Both methods now start with @boundscheck checkbounds(x, inds), like the scalar method and Base's own getindex. Under @inbounds the check is skipped as before.

Verification: new tests cover [0], [4], [1, 4], [-1], 0:1, 3:4 and -1:0; full suite passes locally on Julia 1.3.1 and 1.12.6. Gathering 500,000 sorted indices from a 1M-element, 64-chunk vector takes the same time before and after (about 1.6 ms, within noise on a loaded machine). Merges cleanly before or after the other open ChainedVector PRs.

🤖 Generated with Claude Code

quinnj and others added 2 commits October 15, 2026 11:31
getindex(::ChainedVector, ::AbstractVector{Int}) never checked its
indices, so x[[0]] or x[[-1]] segfaulted and x[[length(x) + 1]] returned
garbage. The UnitRange method read before the first chunk for ranges
starting below 1 before failing.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@quinnj
quinnj merged commit 726105e into main Oct 27, 2026
4 checks passed
@quinnj
quinnj deleted the claude/chained-getindex-bounds branch October 27, 2026 05:06
quinnj referenced this pull request Oct 27, 2026
Bump to 1.4.11. Also fixes a test guard: findmax(f, x) and non-Integer isodd need Julia 1.7.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

1 participant