Skip to content

Fix segfault in NEXUS interleaved format parsing#1985

Open
stevenweaver wants to merge 1 commit into
veg:developfrom
stevenweaver:fix/nexus-interleave-segfault
Open

Fix segfault in NEXUS interleaved format parsing#1985
stevenweaver wants to merge 1 commit into
veg:developfrom
stevenweaver:fix/nexus-interleave-segfault

Conversation

@stevenweaver

Copy link
Copy Markdown
Member

Summary

Fixes a segfault (SIGSEGV) when parsing interleaved NEXUS files generated by R's write.nexus.data.

Root Cause

The non-interleaved sequence length validation check at nexus.cpp:1304 was incorrectly triggering for interleaved alignments. When processing the second interleave block, totalSitesRead increases (expected behavior for interleaved data), but the validation treated this as an error condition.

This caused GetSequenceName(fState.curSpecies) to be called with an out-of-bounds index (curSpecies wraps around in interleaved mode), returning nullptr, which then crashed in _String::Enquote().

Fix

  • Add !fState.interleaved to the condition guard so the non-interleaved validation only applies to non-interleaved files
  • Add null check on GetSequenceName result as a defensive measure

Testing

  • Reproduced the crash with the production dataset (12 taxa, 1602 chars, INTERLEAVE=YES NEXUS from R)
  • Verified SLAC and RELAX both complete successfully with the fix
  • The existing non-interleaved validation logic is unchanged for non-interleaved files

Fixes #1984

The non-interleaved sequence length validation check at nexus.cpp:1304
was incorrectly triggering for interleaved alignments. When processing
the second (or subsequent) interleave blocks, totalSitesRead increases
as expected, but the check treated this as an error.

This caused GetSequenceName(fState.curSpecies) to be called with an
invalid index (since curSpecies wraps around in interleaved mode),
returning nullptr, which then crashed in Enquote().

Fix:
- Skip the non-interleaved validation when fState.interleaved is true
- Add null check on GetSequenceName result as defensive measure

Fixes veg#1984
@stevenweaver stevenweaver reopened this May 4, 2026
@sonarqubecloud

sonarqubecloud Bot commented May 4, 2026

Copy link
Copy Markdown

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.

1 participant