Skip to content

Fix 64-bit index corruption when L and U use a user-supplied work array - #4

Merged
xiaoyeli merged 1 commit into
masterfrom
claude/epic-rubin-j04ke9
Oct 20, 2026
Merged

xiaoyeli merged 1 commit into
masterfrom
claude/epic-rubin-j04ke9

Conversation

@xiaoyeli

Copy link
Copy Markdown
Owner

Summary

Template counterpart of xiaoyeli/superlu#182, applied to SRC/xmemory.base so that regenerated {s,d,c,z}memory.c carry the fix.

With -DXSDK_INDEX_SIZE=64, any call with lwork > 0 (L and U stored in a user-supplied work[] array) corrupted the factors. In the extracted sources this reproduces with:

cmake -B build -DXSDK_INDEX_SIZE=64 -Denable_internal_blaslib=ON
cmake --build build
cd build/TESTING && ./s_test -t "LA" -l 1000000 -n 9

which segfaulted in sPivotGrowth on the first factorization. lwork == 0 and the 32-bit index build were unaffected.

Root cause

In @(pre)LUMemInit, the user-memory branch carves the column pointer arrays xlsub, xlusup and xusub out of work[] with (n+1) * iword bytes each, where iword = sizeof(int). Those arrays are int_t, so with 64-bit indices each gets half the bytes it needs. xusub overruns into the lusup/ucol block placed immediately after it, and the numeric values in turn overwrite the U column pointers. The heap path uses intMalloc(n+1), which is sized correctly.

Changes

  • Allocate xlsub, xlusup and xusub with sizeof(int_t) (new local liword, matching the naming already used in @(pre)memory_usage). xsup and supno remain int.
  • Use sizeof(int_t) for the lsub/usub share in the matching @(pre)user_free of the shrink loop.
  • Make the lwork == -1 estimate count the two int arrays and the three int_t arrays separately, and the lsub/usub blocks with sizeof(int_t).
  • @(pre)StackCompress (currently not called anywhere) computed the byte offsets of the int_t lsub/usub blocks with sizeof(int) and the end of ucol with the integer size instead of the value size. Corrected for consistency.

Verification

The changed lines of this template, with @(pre) and @(type) substituted for the double precision case, are identical to the SRC/dmemory.c diff in xiaoyeli/superlu#182 (31 changed lines). The extracted sources in that PR pass the full ctest suite and every tester with both 32- and 64-bit indices.


Generated by Claude Code

Template counterpart of xiaoyeli/superlu#182.

With XSDK_INDEX_SIZE=64 and lwork > 0, xLUMemInit carved the int_t column
pointer arrays xlsub, xlusup and xusub out of work[] with (n+1)*sizeof(int)
bytes each, half of what they need. xusub overran into the lusup/ucol
storage placed right after it and the numeric values overwrote the U
column pointers, so xgssvx crashed in xPivotGrowth on the first
factorization. The heap path (lwork == 0) was unaffected because it uses
intMalloc.

Size the three int_t arrays, the matching xuser_free in the shrink loop,
and the lwork == -1 estimate with sizeof(int_t); xsup and supno remain
int. Also fix the byte offsets in the (currently unused) xStackCompress,
which computed the positions of the int_t lsub/usub blocks with
sizeof(int) and the end of ucol with the integer size instead of the
value size.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VjnVBdsXEM3c41ssQ3hFAM
@xiaoyeli
xiaoyeli merged commit ed0e6e9 into master Oct 20, 2026
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

Successfully merging this pull request may close these issues.

2 participants