Skip to content

fix: add bounds check for coverage array access - #24

Merged
nh13 merged 2 commits into
mainfrom
fix/23-coverage-bounds-check
Dec 25, 2025
Merged

fix: add bounds check for coverage array access#24
nh13 merged 2 commits into
mainfrom
fix/23-coverage-bounds-check

Conversation

@nh13

@nh13 nh13 commented Dec 22, 2025

Copy link
Copy Markdown
Owner

Summary

  • Add bounds validation before accessing coverage array
  • Prevent potential out-of-bounds memory access

Background

From code review (research.md §1.2, MEDIUM severity):
If graph.coder() returns an unexpected value, the coverage array access could be out-of-bounds, causing memory corruption or crash.

Changes

  • src/caller.cpp: Add index validation before coverage array access, print warning if invalid

Test plan

  • CI workflow passes
  • Coverage calculation still works correctly for valid inputs

Closes #23

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Improved robustness of MSA coverage adjustments by adding bounds validation to avoid invalid index updates.
    • Added diagnostic warnings when a coverage calculation would access out-of-range data, aiding troubleshooting and data integrity.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai

coderabbitai Bot commented Dec 22, 2025

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

Bounds checking added to the pairwise MSA coverage update in src/caller.cpp. The loop index uses size_t, the coverage index is computed into idx and validated against coverage.size() before decrementing; out-of-range indices emit a stderr warning.

Changes

Cohort / File(s) Summary
Bounds check for coverage array access
src/caller.cpp
Loop index changed from int to size_t. Coverage index computed as idx = code * consensus.size() + i and validated (if (idx < coverage.size())) before decrement; emits stderr warning when out of range.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

"I nibble bytes and check each hop,
an index safe, no memory drop.
If idx strays beyond the line,
a warning chirps — all stays fine.
— a careful rabbit 🐇"

Pre-merge checks and finishing touches

❌ Failed checks (1 warning, 1 inconclusive)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
Linked Issues check ❓ Inconclusive The pull request implements bounds validation for coverage array access and emits warnings for invalid indices, meeting the core requirements [#23]. However, test cases for edge cases are not apparent from the changeset summary. Confirm whether unit tests covering edge cases for coverage array calculation were added, as required by issue #23.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The pull request title accurately describes the main change: adding bounds check for coverage array access, which is the primary objective of the changeset.
Out of Scope Changes check ✅ Passed All changes are scoped to the coverage bounds check implementation in src/caller.cpp, with no unrelated modifications detected.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/23-coverage-bounds-check

📜 Recent review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 31af6cb and 7dbb95d.

📒 Files selected for processing (1)
  • src/caller.cpp
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/caller.cpp

Comment @coderabbitai help to get the list of available commands and usage tips.

@nh13
nh13 force-pushed the fix/21-file-open-error branch from f5be4e9 to 6662c3a Compare December 22, 2025 23:05
@nh13
nh13 force-pushed the fix/23-coverage-bounds-check branch from 2448bec to 02ccc49 Compare December 22, 2025 23:05
@nh13
nh13 force-pushed the fix/21-file-open-error branch from 6662c3a to a691eb5 Compare December 22, 2025 23:10
@nh13
nh13 force-pushed the fix/23-coverage-bounds-check branch from 02ccc49 to 51e601c Compare December 22, 2025 23:10
@nh13
nh13 force-pushed the fix/21-file-open-error branch from a691eb5 to f8177ba Compare December 22, 2025 23:11
@nh13
nh13 force-pushed the fix/23-coverage-bounds-check branch from 51e601c to 134a617 Compare December 22, 2025 23:12
@nh13
nh13 force-pushed the fix/21-file-open-error branch from f8177ba to 8eca760 Compare December 22, 2025 23:22
@nh13
nh13 force-pushed the fix/23-coverage-bounds-check branch from 134a617 to 31af6cb Compare December 22, 2025 23:22
@nh13

nh13 commented Dec 23, 2025

Copy link
Copy Markdown
Owner Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Dec 23, 2025

Copy link
Copy Markdown
✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8eca760 and 31af6cb.

📒 Files selected for processing (1)
  • src/caller.cpp

Comment thread src/caller.cpp
@nh13
nh13 force-pushed the fix/21-file-open-error branch 2 times, most recently from 9af06b4 to b292711 Compare December 24, 2025 16:28
Base automatically changed from fix/21-file-open-error to main December 24, 2025 16:29
nh13 and others added 2 commits December 24, 2025 09:30
Add validation before accessing coverage array to prevent potential
out-of-bounds memory access if graph.coder() returns unexpected value.

- Check index is within coverage.size() before access
- Print warning message if invalid index detected
- Use size_t for loop variable to match container size type

Closes #23

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Include code, idx, and coverage.size() in the warning message to aid
debugging invalid coverage index issues.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@nh13
nh13 force-pushed the fix/23-coverage-bounds-check branch from 605506f to 7dbb95d Compare December 24, 2025 16:31
@nh13
nh13 merged commit d8d18dc into main Dec 25, 2025
2 checks passed
@nh13
nh13 deleted the fix/23-coverage-bounds-check branch December 25, 2025 01:51
@coderabbitai coderabbitai Bot mentioned this pull request Dec 26, 2025
2 tasks
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.

Add bounds check for coverage array access

1 participant