dorcsd2by1/uncsd2by1: avoid OOB access with zero rows#1291
Open
jschueller wants to merge 1 commit into
Open
Conversation
When P=0 and M=Q (U2 is M-by-M, X21 is M-by-M and orthogonal), or P=M and M=Q (U1 is M-by-M, X11 is M-by-M and orthogonal), or Q=0, the minimal dimension R = MIN(P, M-P, Q, M-Q) is zero, so C and S are empty. In these degenerate cases the preceding code entered the R == P or R == M-P branch and called the bidiagonalization subroutines (SORBDB2/SORBDB3) which then accessed elements X21(I,I+1) or X11(I,I+1) out of bounds in the second DO loop (I = P+1, Q or I = M-P+1, Q). Fix: handle R = 0 directly in the four driver routines before the case-dependent bidiagonalization path. The three trivial CSD cases are: Q = 0: set U1 = I, U2 = I, return. P = 0, M = Q: copy X21 to U2, set V1T = I, return. P = M, M = Q: copy X11 to U1, set V1T = I, return. All other R=0 configurations are non-standard and still fall through to the existing path (which may fail). Fixes Reference-LAPACK#549
martin-frbg
approved these changes
Jun 11, 2026
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.
When P=0 and M=Q (U2 is M-by-M, X21 is M-by-M and orthogonal), or P=M and M=Q (U1 is M-by-M, X11 is M-by-M and orthogonal), or Q=0, the minimal dimension R = MIN(P, M-P, Q, M-Q) is zero, so C and S are empty. In these degenerate cases the preceding code entered the R == P or R == M-P branch and called the bidiagonalization subroutines (SORBDB2/SORBDB3) which then accessed elements X21(I,I+1) or X11(I,I+1) out of bounds in the second DO loop (I = P+1, Q or I = M-P+1, Q).
Fix: handle R = 0 directly in the four driver routines before the case-dependent bidiagonalization path. The three trivial CSD cases are:
Q = 0: set U1 = I, U2 = I, return.
P = 0, M = Q: copy X21 to U2, set V1T = I, return.
P = M, M = Q: copy X11 to U1, set V1T = I, return.
All other R=0 configurations are non-standard and still fall through to the existing path (which may fail).
Fixes #549