Skip to content

[MRG] Fix BSP-OT crashes on empty plans and invalid initial permutations - #930

Open
xihaian251 wants to merge 2 commits into
PythonOT:masterfrom
xihaian251:fix/bspot-native-input-safety
Open

xihaian251 wants to merge 2 commits into
PythonOT:masterfrom
xihaian251:fix/bspot-native-input-safety

Conversation

@xihaian251

Copy link
Copy Markdown
Contributor

Summary

ot.bsp.compute_bspot_bijection had two distinct native-safety defects on empty or degenerate inputs, both reproduced against a freshly compiled extension from current master:

  1. n_plans=0 produced an empty candidate vector. MergePlansNoPar (ot/bsp/BSP-OT_header_only.h) then indexed plans[0] / plans[I[0]], giving SIGSEGV (exit 139) through both the public API and the direct Cython entry point. Negative counts are rejected earlier by np.zeros((-1, n)) on unmodified master; the patch rejects all non-positive integers for a deterministic contract.
  2. A non-permutation initial_perm (negative, out-of-range or duplicate entries) reached BijectiveMatching::getInverse, where TI[T[i]] = i writes 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 raises ValueError.

These affect the compute_bspot_bijection / bsp_solve_c path, not the merge_bijections entry point fixed by #911.

Fix

Validation

Fresh source builds of both patched and unmodified master (Ubuntu 24.04, g++ 13.3, Python 3.12, Eigen 3.4):

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-integral n_plans coercion is a separate contract question, not a native-safety defect. No CI result is claimed here.

@codecov

codecov Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.10%. Comparing base (367355d) to head (f17b043).

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:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@xihaian251

Copy link
Copy Markdown
Contributor Author

Hi @baptiste-genest,
When convenient, would you be willing to review PR #930?
It addresses two native-safety issues in BSP-OT: n_plans=0 causes a SIGSEGV when merging an empty candidate list, while invalid initial_perm values can cause out-of-bounds writes or hangs.
Both issues were reproduced against a freshly compiled master extension. The patched extension rejects these inputs with ValueError; the focused tests pass (41 passed, 1 skipped), and all upstream CI checks are green.
I would particularly appreciate your view on the Python/Cython validation. Following the simplification discussed in #911, I considered removing the Cython checks, but direct calls to bsp_solve_c independently reproduce the native failures. I therefore kept guards at both entry points.
Would you prefer a different balance between safety and avoiding duplicate validation?
Thanks!

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant