Guard out-of-bounds accesses in SisoZpk minreal#1060
Merged
Conversation
The pole-zero cancellation loop accessed `newZ[zidx+1]` (assuming the matched complex zero has a conjugate partner immediately after it) and `sys.p[pidx]` after `pidx += 1` (assuming another pole exists) without bounds checks. Both raise `BoundsError` on malformed inputs (or inputs that become so after earlier `deleteat!` operations). Add a `zidx < length(newZ)` check before the conjugate-cleanup, and break out of the loop after incrementing `pidx` past the available poles (still removing the matched zero for consistency). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
This is an automated message.
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1060 +/- ##
==========================================
- Coverage 91.61% 91.55% -0.07%
==========================================
Files 42 42
Lines 5653 5660 +7
==========================================
+ Hits 5179 5182 +3
- Misses 474 478 +4 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Construct complex-valued zpk inputs that exercise both unguarded accesses in the cancellation loop (lines 83 and 87 of SisoZpk.jl): one where a real pole matches a -imag complex zero whose conjugate partner was already deleted (newZ[zidx+1] out of bounds), and one where a complex pole at the last index is increment-matched past the end of sys.p. Both inputs threw BoundsError on master and now return the fully cancelled `zpk([], [], k)`. Co-Authored-By: Claude Opus 4.7 (1M context) <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
minreal(::SisoZpk, eps)had two unguarded accesses in the pole-zero cancellation loop:newZ[zidx+1] = real(newZ[zidx+1])assumed the matched complex zero had a conjugate partner immediately after it.pidx += 1,sys.p[pidx]was indexed without checking whether another pole existed.Both raise
BoundsErroron malformed inputs or on inputs that become so after the loop's earlierdeleteat!operations. The fix adds the missing checks (still removing the matched zero in the second case for consistency).Test plan
test_zpk.jl/ minreal tests.SisoZpk(e.g. a complex zero at the end of thezvector without its conjugate partner) and verifyminrealno longer throws.🤖 Generated with Claude Code