Skip to content

fix: Avoid double panic in buf_ring destructor#95

Merged
Nehliin merged 1 commit intomasterfrom
fix-panic
Feb 1, 2026
Merged

fix: Avoid double panic in buf_ring destructor#95
Nehliin merged 1 commit intomasterfrom
fix-panic

Conversation

@Nehliin
Copy link
Copy Markdown
Owner

@Nehliin Nehliin commented Feb 1, 2026

the check in the destructor is only there for non panicking code that forgets to unregister the buffer

@Nehliin Nehliin merged commit 6c801fb into master Feb 1, 2026
3 checks passed
grenade added a commit to grenade/vortex that referenced this pull request Apr 5, 2026
- Add bounds check before slicing buffer in disk read completion
  handler (event_loop.rs). Logs error instead of panicking when
  end_idx exceeds buffer length.

- Guard Buffer::drop panic with std::thread::panicking() to prevent
  double-panic abort. Follows the same pattern already applied to
  BufferRing::drop in PR Nehliin#95.
grenade added a commit to grenade/vortex that referenced this pull request Apr 9, 2026
- Add bounds check before slicing buffer in disk read completion
  handler (event_loop.rs). Logs error instead of panicking when
  end_idx exceeds buffer length.

- Guard Buffer::drop panic with std::thread::panicking() to prevent
  double-panic abort. Follows the same pattern already applied to
  BufferRing::drop in PR Nehliin#95.
grenade added a commit to grenade/vortex that referenced this pull request Apr 13, 2026
The end_idx computation used piece_len.min(SUBPIECE_SIZE) which always
resolved to SUBPIECE_SIZE (16384) for normal pieces. When piece_length
is not a multiple of SUBPIECE_SIZE (e.g. 1986560 = 121*16384 + 4096),
the last subpiece starts at offset 1982464 and is only 4096 bytes, but
end_idx was computed as 1982464 + 16384 = 1998848, overflowing the
buffer of 1986560 bytes.

Fix: cap end_idx at piece_len instead of adding a fixed SUBPIECE_SIZE.

The buf_pool.rs panicking() guard (matching the existing BufferRing::drop
pattern from PR Nehliin#95) is retained as defense-in-depth.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Nehliin pushed a commit that referenced this pull request Apr 14, 2026
…124)

* fix: correct subpiece slice bounds for non-power-of-2 piece lengths

The end_idx computation used piece_len.min(SUBPIECE_SIZE) which always
resolved to SUBPIECE_SIZE (16384) for normal pieces. When piece_length
is not a multiple of SUBPIECE_SIZE (e.g. 1986560 = 121*16384 + 4096),
the last subpiece starts at offset 1982464 and is only 4096 bytes, but
end_idx was computed as 1982464 + 16384 = 1998848, overflowing the
buffer of 1986560 bytes.

Fix: cap end_idx at piece_len instead of adding a fixed SUBPIECE_SIZE.

The buf_pool.rs panicking() guard (matching the existing BufferRing::drop
pattern from PR #95) is retained as defense-in-depth.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* style: fix rustfmt formatting in event_loop.rs

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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