CBLAS: fix infinite loop in c/z gemv and gbmv (RowMajor, ConjTrans, M=0) - #1374
Closed
EylonKrause wants to merge 1 commit into
Closed
CBLAS: fix infinite loop in c/z gemv and gbmv (RowMajor, ConjTrans, M=0)#1374EylonKrause wants to merge 1 commit into
EylonKrause wants to merge 1 commit into
Conversation
In cblas_cgemv, cblas_zgemv, cblas_cgbmv and cblas_zgbmv, the
CblasRowMajor + CblasConjTrans path conjugates Y only inside
`if (M > 0) { ... if (N > 0) { ... } }`, where the loop stride `i` and the
sentinel `st` are assigned. The post-call restore loop that un-conjugates Y is
gated on `if (N > 0)` alone.
When M == 0 and N > 0 the forward conjugation is skipped, so `i` stays 0 and
`st` stays NULL. The restore loop then runs
`do { *y = -(*y); y += i; } while (y != st);` with i == 0 and st == NULL, so y
never advances and never reaches st -- an infinite loop that also repeatedly
negates Y[0]. A normal M > 0 ConjTrans call is unaffected.
Gate the un-conjugation on the same condition under which Y was conjugated
(M > 0 && N > 0).
Verified against a build of the same wrappers (BLIS's copy of the netlib CBLAS
layer): cblas_cgbmv(CblasRowMajor, CblasConjTrans, M=0, N=2, ...) hangs (killed
by a 5s timeout) before the change and returns immediately with Y unchanged
after it; likewise for the gemv path.
Signed-off-by: Eylon Krause <eylon1909@gmail.com>
langou
approved these changes
Aug 29, 2026
Contributor
|
Thanks @EylonKrause ! Well spotted, great fix. |
❌ 4 Tests Failed:
View the full list of 4 ❄️ flaky test(s)
To view more test analytics, go to the Test Analytics Dashboard |
Author
|
Closing this — I'll route this fix through a different channel rather than here. Sorry for the noise. |
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.
Problem
The hand-written row-major shims in the C interface loop forever on a valid (if degenerate) call.
In
cblas_cgemv,cblas_zgemv,cblas_cgbmvandcblas_zgbmv, theCblasRowMajor+CblasConjTranspath conjugatesY(and sets the loop strideiand the sentinelst) only inside:but the post-call loop that un-conjugates
Yis gated onif (N > 0)alone:When
M == 0andN > 0, the forward block is skipped, soiis still0andstis stillNULL. The restore loop then advancesyby0and compares againstNULL, so it never terminates — an infinite loop that also keeps negatingY[0].M = 0is a documented, in-range argument for these routines (xerblaonly rejectsM < 0), so this is reachable from a conforming caller.Fix
Gate the un-conjugation on the same condition under which
Ywas conjugated,if (M > 0 && N > 0), in all four files. One line each; a normalM > 0ConjTrans call is byte-for-byte unchanged.Reproducer / validation
BLIS carries a copy of these same netlib CBLAS wrappers, so I reproduced it there against a real build:
Linked against the unpatched wrapper this is killed by a 5 s timeout; with the one-line gate it returns immediately and leaves
Yunchanged. Thegemvpath behaves the same way.Disclosure: this contribution was authored with an AI coding assistant (Claude) and reviewed and validated before submission.