Skip to content

pdgbtrf potential buffer overrun #117

Open
@TLCFEM

Description

@TLCFEM

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions