fix: reject negative entries in numpy-array cone dims#204
Merged
Conversation
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>
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.
Summary
get_cone_arr_diminscs/scsobject.hhandles three input shapes for integer cone fields (q,s,cs, etc.):parse_pos_scs_int(rejects negatives)get_pos_int_param→parse_pos_scs_int(rejects negatives)memcpyintoscs_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:
Fix
After the
memcpy, walk the copied entries andprintErr(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
qands, all asserting:Full suite locally:
334 passed, 66 skipped.Independent of #201 / #202 / #203 — touches only
scs/scsobject.h(disjoint from #201) andtest/test_scs_coverage.py(disjoint from others).🤖 Generated with Claude Code