Skip to content

Conversation

@nh13
Copy link
Owner

@nh13 nh13 commented Dec 22, 2025

Summary

  • Clamp distance d to valid range to prevent negative/invalid values from normal distribution
  • Use 64-bit arithmetic for range calculation to prevent integer overflow
  • Skip iteration if calculated range is invalid

Closes #96

Root Cause

When generating paired-end reads, the distance d is calculated from a normal distribution. With extreme values (e.g., -10 sigma), d can become negative, causing:

  1. The expression (l - d + 1) to overflow
  2. Reads to be generated from incorrect positions

Changes

Both occurrences in dwgsim_core() are fixed:

  • Lines 646-660 (standard case)
  • Lines 669-683 (regions_bed case)

Test plan

  • Verify build succeeds
  • Run integration tests (make test-integration)
  • Manually test with high std_dev values to verify no crashes

🤖 Generated with Claude Code

@coderabbitai
Copy link

coderabbitai bot commented Dec 22, 2025

Warning

Rate limit exceeded

@nh13 has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 4 minutes and 49 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 29c3b7d and bee7150.

📒 Files selected for processing (1)
  • src/dwgsim.c
✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/integer-overflow-position-calculation

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

…n calculation

- Clamp distance `d` to valid range [min_dist, l] where min_dist = read1_len + read2_len
- Use 64-bit arithmetic for range calculation to prevent overflow
- Skip iteration if calculated range is invalid

This fixes issues where extreme values from the normal distribution could cause:
1. Negative distance values leading to incorrect position calculations
2. Integer overflow in (l - d + 1) expression

Closes #96

🤖 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/integer-overflow-position-calculation branch from 88ea032 to bee7150 Compare December 22, 2025 23:17
@nh13
Copy link
Owner Author

nh13 commented Dec 22, 2025

@coderabbitai review

@coderabbitai
Copy link

coderabbitai bot commented Dec 22, 2025

✅ 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.

@nh13 nh13 merged commit 26e3aa9 into main Dec 22, 2025
2 checks passed
@nh13 nh13 deleted the fix/integer-overflow-position-calculation branch December 22, 2025 23:18
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.

fix: integer overflow and negative distance in position calculation

2 participants