Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pdgbtrf potential buffer overrun #117

Open
TLCFEM opened this issue Mar 7, 2025 · 0 comments
Open

pdgbtrf potential buffer overrun #117

TLCFEM opened this issue Mar 7, 2025 · 0 comments

Comments

@TLCFEM
Copy link

TLCFEM commented Mar 7, 2025

The DLAMOV call in the following implies the size of A be DBPTR + ( LLDA - 1 ) * BN, if the trailing LLDA - 1 - BM elements are not accessed, this number is DBPTR + ( LLDA - 1 ) * BN - ( LLDA - 1 - BM ).

scalapack/SRC/pdgbtrf.f

Lines 817 to 837 in a23c2cd

IF( MYCOL.NE.NPCOL-1 ) THEN
BM = BW - LBWU
BN = BW
ELSE
BM = MIN( BW, ODD_SIZE ) + BWU
BN = MIN( BW, ODD_SIZE )
END IF
*
* Pointer to first element of block bidiagonal matrix in AF
* Leading dimension of block bidiagonal system
*
BBPTR = ( NB+BWU )*BW + 1
LDBB = 2*BW + BWU
*
* Copy from A and AF into block bidiagonal matrix (tail of AF)
*
* DBPTR = Pointer to diagonal blocks in A
DBPTR = BW + 1 + LBWU + LN*LLDA
*
CALL DLAMOV( 'G', BM, BN, A( DBPTR ), LLDA-1, AF( BBPTR+BW*LDBB ),
$ LDBB )

From the assignment, assuming 1x1 grid, then LBWU = BWU, LN = N - BW, BN = BW, BM = BW + BWU.

scalapack/SRC/pdgbtrf.f

Lines 699 to 718 in a23c2cd

IF( MYCOL.NE.0 ) THEN
LBWL = BW
LBWU = 0
APTR = 1
ELSE
LBWL = BWL
LBWU = BWU
APTR = 1 + BWU
END IF
*
IF( MYCOL.NE.NPCOL-1 ) THEN
LM = NB - LBWU
LN = NB - BW
ELSE IF( MYCOL.NE.0 ) THEN
LM = ODD_SIZE + BWU
LN = MAX( ODD_SIZE-BW, 0 )
ELSE
LM = N
LN = MAX( N-BW, 0 )
END IF

The number is

  BW + 1 + BWU + ( N - BW ) * LLDA + ( LLDA - 1 ) * BN - ( LLDA - 1 - BM ) - 1
= BW + 1 + BWU + N * LLDA - BW * LLDA + ( LLDA - 1 ) * BW - ( LLDA - 1 - BW - BWU ) - 1
= BW + 1 + BWU + N * LLDA - BW * LLDA + LLDA * BW -  BW - LLDA + 1 + BW + BWU - 1
= BW + 1 + 2 * BWU - LLDA + N * LLDA

So apart from the block N * LLDA, there is an additional part BW + 1 + 2 * BWU - LLDA.
If LLDA = 2 * BW +1, and BW = BWU + BWL, then

BW + 1 + 2 * BWU - LLDA = BW + 1 + 2 * BWU - 2 * BW - 1 = 2 * BWU - BW = BWU - BWL

If BWU is different from BWL, A needs to be extended to avoid buffer overrun.

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

No branches or pull requests

1 participant