Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[BUG] out-of-bounds write in SUNMatScaleAddI_Sparse #581

@dweindl

Description

@dweindl

Current Behavior:

For the example below, I encounter out-of-bounds writes in SUNMatScaleAddI_Sparse at

https://github.com/LLNL/sundials/blob/c28eaa3764a03705d61decb6025b409360e9d53f/src/sunmatrix/sparse/sunmatrix_sparse.c#L753

Expected Behavior:

No out-of-bounds writes.

Steps To Reproduce:

  • Download test_SUNMatScaleAddI_Sparse.tar.gz

  • Unpack: tar -xzf test_SUNMatScaleAddI_Sparse.tar.gz && cd test_SUNMatScaleAddI_Sparse

  • Configure & build: cmake -S. -Bbuild && cmake --build build (this might need some adaptation to find the sundials configuration)

  • valgrind build/sparsetest:

     Invalid write of size 8
        at 0x10C882: SUNMatScaleAddI_Sparse (sunmatrix_sparse.c:753)
        by 0x111B9C: SUNMatScaleAddI (sundials_matrix.c:201)
        by 0x109630: main (in build/sparsetest)
      Address 0x4a8f588 is 8 bytes before a block of size 312 alloc'd
        at 0x484D953: calloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
        by 0x109D07: SUNSparseMatrix (sunmatrix_sparse.c:130)
        by 0x10943F: main (in build/sparsetest)
     
     Invalid write of size 8
        at 0x10C8C4: SUNMatScaleAddI_Sparse (sunmatrix_sparse.c:754)
        by 0x111B9C: SUNMatScaleAddI (sundials_matrix.c:201)
        by 0x109630: main (in build/sparsetest)
      Address 0x4a8f408 is 8 bytes before a block of size 312 alloc'd
        at 0x484D953: calloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
        by 0x109C81: SUNSparseMatrix (sunmatrix_sparse.c:127)
        by 0x10943F: main (in build/sparsetest)
    

Environment:

  • SUNDIALS version: 7.1.1
  • OS: Ubuntu 24.04
  • Compiler: gcc 13.2.0

Anything else:

Running the same example with SUNMatScaleAddI_Sparse from sundials 6.6.2 works as expected.
It seems the problem was introduced in #257.

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