Repository navigation
[MRG] Fix BSP-OT crashes on empty plans and invalid initial permutations - #930
xihaian251 wants to merge 2 commits into
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #930 +/- ##
==========================================
+ Coverage 97.09% 97.10% +0.01%
==========================================
Files 130 130
Lines 27229 27271 +42
==========================================
+ Hits 26437 26482 +45
+ Misses 792 789 -3 🚀 New features to boost your workflow:
|
|
Hi @baptiste-genest, |
Summary
ot.bsp.compute_bspot_bijectionhad two distinct native-safety defects on empty or degenerate inputs, both reproduced against a freshly compiled extension from current master:n_plans=0produced an empty candidate vector.MergePlansNoPar(ot/bsp/BSP-OT_header_only.h) then indexedplans[0]/plans[I[0]], giving SIGSEGV (exit 139) through both the public API and the direct Cython entry point. Negative counts are rejected earlier bynp.zeros((-1, n))on unmodified master; the patch rejects all non-positive integers for a deterministic contract.initial_perm(negative, out-of-range or duplicate entries) reachedBijectiveMatching::getInverse, whereTI[T[i]] = iwrites out of bounds (ASan heap-buffer-overflow WRITE, line 817) or hangs the merge loop. On freshly built extensions, unmodified master times out (public API) / SIGABRT (Cython); the patch raisesValueError.These affect the
compute_bspot_bijection/bsp_solve_cpath, not themerge_bijectionsentry point fixed by #911.Fix
n_plans > 0at both the public API and the Cython boundary.initial_permto be an exact integer permutation (dtype.kind in "iu"andsort(ip) == arange(n)) in Python, with the equivalentsort == arangecheck on Cython's typed int buffer; short buffers are rejected before the native pointer copy.if (plans.empty()) return T;toMergePlansNoParas a last-resort native guard.Validation
Fresh source builds of both patched and unmodified master (Ubuntu 24.04, g++ 13.3, Python 3.12, Eigen 3.4):
pytest -q test/test_bspot.py: 41 passed, 1 skipped (exit 0), including the new boundary tests and the existing [MRG] Make BSP-OT random seeding reproducible across calls #898/[MRG] Read the number of plans from axis 0 in merge_bijections #911 tests.ValueErrorwith exit 0 in every case.git diff --check, and forward/reversegit apply --checkpass.Scope
The accepted input set is unchanged (C-contiguous int32 permutation or
None);int64, list and non-contiguous arrays were already rejected by the typed Cython buffer on master, as confirmed by direct A/B. Non-integraln_planscoercion is a separate contract question, not a native-safety defect. No CI result is claimed here.