Skip to content

Calling ?GEEV with non-finite input leads to memory corruption in ?LASCAL #1128

Closed

Description

@martin-frbg

Description
See OpenMathLib/OpenBLAS#5250 for full context and reproducer
Calling ?GEEV with non-finite input will fail in ?HSEQR. ?GEEV will then invoke ?LASCAL to undo any previous scaling of the input data, using INFO as a reference - with the existing guard for INFO.GT.0 covering only half the invocations.
The trivial fix would be to move the existing check for INFO.GT.0 into the outer if (?CALEA) THEN conditional - or add a check for INFO.GE.0 there. The same problem appears to be present in ?GEEVX, though I have not checked in detail.
Checklist

  • I've included a minimal example to reproduce the issue
  • I'd be willing to make a PR to solve this issue

Activity

  1. changed the title [-]Calling ?GEEV with non-finite input leads to memory corruption from array underruns in ?LASCAL[/-] [+]Calling ?GEEV with non-finite input leads to memory corruption in ?LASCAL[/+] on May 17, 2025
  2. angsch commented on Jun 2, 2025

    @angsch
    Collaborator

    Does the reproducer you linked in the issue work for reference-LAPACK on your side? When I execute the reproducer, GEBAL triggers XERBLA ( ** On entry to DGEBAL parameter number 3 had an illegal value), which immediately calls STOP. So everything is fine, no memory corruption, HSEQR is never reached.

    Irrespective of the exact cause, I think that the best way of handling Inf and/or NaN in GEEV (and likely quite a few other routines) is to just return if the input matrix does not contains only valid floating point numbers. A natural point to check for Inf/NaN is

    lapack/SRC/dgeev.f

    Lines 348 to 356 in 2475f7b

    ANRM = DLANGE( 'M', N, N, A, LDA, DUM )
    SCALEA = .FALSE.
    IF( ANRM.GT.ZERO .AND. ANRM.LT.SMLNUM ) THEN
    SCALEA = .TRUE.
    CSCALE = SMLNUM
    ELSE IF( ANRM.GT.BIGNUM ) THEN
    SCALEA = .TRUE.
    CSCALE = BIGNUM
    END IF

    Since problems with Inf/NaN will likely pop up every now and then, should there be a function DISFINITE, inspired by the existing DISNAN, to check for Inf or NaN? Then a possibility is to continue the above code snippet like this:

        ELSE IF( DISFINITE( ANRM) ) THEN
            INFO = ... <new info flag for GEEV that signals that Inf/NaN is encountered>
            CALL XERBLA( 'DGEEV', -INFO)
            RETURN
        END
    
  3. reopened this on Jun 15, 2025
  4. langou commented on Jun 15, 2025

    @langou
    Contributor

    I am reopening this issue because, I think we should, in addition, also work on the suggestion of @angsch

    As opposed to DISFINITE, I would have used DISNAN and let GEEV proceeds even if there are infinite entries. I feel some people would expect LAPACK to return INFO = 0 if we input a diagonal matrix with Inf on the diagonal. I do not have a strong opinion though. Note that ANRM can be infinite and A only have finite entries but that would an extreme corner case and I would think that LAPACK can, in general, not handle these matrices.

  5. added a commit that references this issue on Jun 15, 2025
  6. martin-frbg commented on Jun 26, 2025

    @martin-frbg
    CollaboratorAuthor

    @angsch sorry for the late response, indeed the crucial difference is that the OpenBLAS XERBLA does not do an immediate exit() corresponding to the Fortran STOP, but returns to the caller after printing the message. This may be the more benign
    behaviour compared to a library crashing user code, and it has been like that since the original GotoBLAS of about 20 years ago, but of course it only works if the caller can be expected to return() immediately as well. This problem must have arisen when it was decided to incorporate the Reference-LAPACK sources into OpenBLAS, some months before I took over the maintainer role. (And I guess it must have been a gamble which flavor of xerbla would get called in a combined build before that.)
    I'll prepare a PR to revert my change, and see if I can come up with a somewhat sensible solution on the OpenBLAS side

  7. added 9 commits that reference this issue on Jun 10, 2026
    babf490
    8cfb942
    8ce2cb8
    8a0342c
    1a695c2
    a2f5c00
    9c6b029
    a2c717f
    91c0f61
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions