Repository navigation
Reject sample and ancestor IDs equal to num_nodes in link_ancestors (fixes #3484) - #3492
Closed
asystemoffields wants to merge 2 commits into
Closed
asystemoffields wants to merge 2 commits into
asystemoffields wants to merge 2 commits into
Conversation
ancestor_mapper_init_samples and ancestor_mapper_init_ancestors checked IDs with `> num_rows` instead of `>= num_rows`, so an ID equal to the number of nodes passed validation and was then used to index is_sample, is_ancestor and the ancestor map arrays, all allocated with exactly num_nodes entries. A standalone call with such an ID segfaults. Use `>=`, add the one-past-the-end case to the C and Python error tests, and fix test_link_ancestors in test_python_c.py, which asked for ancestor 3 of a tree sequence with nodes 0-2 and only passed because of the bug. Fixes tskit-dev#3484 Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Member
|
I think this is the same as #3489, which is waiting to be merged. But thanks for the extra spot @asystemoffields |
Member
|
Closed as dupe of #3489 |
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.
Description
Fixes #3484
ancestor_mapper_init_samplesandancestor_mapper_init_ancestorsvalidated node IDs with> nodes.num_rowsinstead of>= nodes.num_rows, so a sample or ancestor ID equal to the number of nodes passed the check and was then used to indexis_sample,is_ancestorand the ancestor map arrays, all allocated with exactlynum_nodesentries. A standalone C program callingtsk_table_collection_link_ancestorswith such an ID on a three-node table segfaults; through the Python API,tables.link_ancestors(samples=[0, 1], ancestors=[num_nodes])on a two-sample msprime tree sequence returned normally.c/tskit/tables.c:>=in both checks, so these IDs returnTSK_ERR_NODE_OUT_OF_BOUNDSlike the other node bounds checks in the file.c/tests/test_tables.c:test_link_ancestors_input_errorsgains the one-past-the-end sample and ancestor cases. On the current code these two assertions happen to pass on the seven-node test table (the out-of-bounds accesses land in allocator padding and the run completes), so the C test documents the behaviour rather than catching the regression; the Python test below does fail without the fix.python/tests/test_python_c.py: two cases added totest_link_ancestors_bad_args(fail onmain, pass with the fix).test_link_ancestorsin the same file asked for ancestor 3 of a tree sequence with nodes 0–2 and only passed because of this bug; it now asks for the root, node 2.c/CHANGELOG.rstandpython/CHANGELOG.rst; the:pr:numbers will be filled in once this PR exists.Testing here:
ninja -C build test_tables && ./build/test_tables(CUnit built from source locally): 34208 asserts, 0 failures;pytest python/tests/test_python_c.py python/tests/test_topology.py python/tests/test_highlevel.py python/tests/test_immutable_table_collection.py -k link_ancestors: 110 passed, 6 skipped; clang-format reports no changes.PR Checklist:
Prepared with Claude Code (Claude Fable 5.1) and submitted on the account owner's authorisation; the runs above were done as described.
🤖 Generated with Claude Code