Skip to content

Fix get_file_name segfault: use 1-based index#25

Merged
mawad-amd merged 1 commit intomainfrom
muhaawad/fix-get-file-name-index
Mar 23, 2026
Merged

Fix get_file_name segfault: use 1-based index#25
mawad-amd merged 1 commit intomainfrom
muhaawad/fix-get-file-name-index

Conversation

@mawad-amd
Copy link
Member

Summary

  • get_file_name(name, 0) causes a segfault because the C++ implementation uses 1-based indexing: file_names_[index-1]
  • With index=0, index-1 underflows to SIZE_MAX on unsigned size_t, causing an out-of-bounds access
  • The assert in the C++ code (assert(index <= file_names_.size())) incorrectly allows index=0 and is stripped in release builds anyway
  • This was the flaky CI failure on main — it segfaults depending on memory layout

Fix

Changed get_file_name(name, 0) to get_file_name(name, 1) in the test.

The C++ side should also be hardened (bounds check instead of assert, or switch to 0-based indexing), but that's a separate change.

Co-Authored-By: Claude Opus 4.6 noreply@anthropic.com

The C++ getFileName does file_names_[index-1], so index=0 causes
unsigned underflow and a segfault. Use index=1 (first file).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@mawad-amd mawad-amd merged commit 545d7b8 into main Mar 23, 2026
1 check passed
@mawad-amd mawad-amd deleted the muhaawad/fix-get-file-name-index branch March 23, 2026 07:37
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