Skip to content

fix: reject negative entries in numpy-array cone dims#204

Merged
bodono merged 1 commit into
masterfrom
fix/cone-array-negative-validation
Apr 22, 2026
Merged

fix: reject negative entries in numpy-array cone dims#204
bodono merged 1 commit into
masterfrom
fix/cone-array-negative-validation

Conversation

@bodono

@bodono bodono commented Apr 22, 2026

Copy link
Copy Markdown
Owner

Summary

get_cone_arr_dim in scs/scsobject.h handles three input shapes for integer cone fields (q, s, cs, etc.):

  • Python listparse_pos_scs_int (rejects negatives)
  • bare scalarget_pos_int_paramparse_pos_scs_int (rejects negatives)
  • numpy array → straight memcpy into scs_int * (no sign check)

The array branch thus let negatives slip past Python-side validation. They'd then surface as a misleading "ScsWork allocation error!" ValueError, with SCS core printing "soc cone dimension error" to stderr before failing workspace init.

Reproduced locally:

>>> scs.SCS(..., {"q": [-1]}, ...)
ValueError: Invalid value for cone field 'q'
>>> scs.SCS(..., {"q": -1}, ...)
ValueError: Invalid value for cone field 'q'
>>> scs.SCS(..., {"q": np.array([-1])}, ...)
soc cone dimension error                          # <-- to stderr, from SCS core
cone validation error
ValueError: ScsWork allocation error!              # <-- wrong & generic

Fix

After the memcpy, walk the copied entries and printErr(key) on any negative — same error shape the list/scalar branches produce.

Tests

Added parametrized tests covering list, scalar, and numpy-array inputs for cone fields q and s, all asserting:

ValueError: Invalid value for cone field '<key>'

Full suite locally: 334 passed, 66 skipped.

Independent of #201 / #202 / #203 — touches only scs/scsobject.h (disjoint from #201) and test/test_scs_coverage.py (disjoint from others).

🤖 Generated with Claude Code

get_cone_arr_dim's list and scalar branches both route through
parse_pos_scs_int / get_pos_int_param, which reject negatives. The
numpy-array branch memcpy'd straight into scs_int*, letting negative
values slip past Python-side validation and surface as a misleading
"ScsWork allocation error!" from SCS core (with "soc cone dimension
error" printed to stderr by the C solver).

After the memcpy, loop over the copied entries and printErr on any
negative — matching the list/scalar error shape
"Invalid value for cone field '<key>'".

Added parametrized tests asserting parity across list / scalar / numpy
inputs for cone fields q and s.

Full suite: 334 passed, 66 skipped.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@bodono
bodono merged commit 0a3f204 into master Apr 22, 2026
34 checks passed
@bodono
bodono deleted the fix/cone-array-negative-validation branch April 22, 2026 20:52
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