`size_hint` overflow panic for unbounded source

Đang mở
#935 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

@voidsipp đang làm issue này rồi.

Từ ngày 3/11/2026.

  • #936 của @voidsipp — đang mở

Đánh giá

Độ khó
3/5
Thời gian dự kiến
Nửa ngày
Mức phù hợp với người mới
58/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
rust
Lĩnh vực
audio-video-rtc

Hướng nghiên cứu

Start with ChannelCountConverter::size_hint in src/conversions/channels.rs (around lines 94-99), where the size-hint arithmetic overflows when the source reports (usize::MAX, None). Then check MixerSource::size_hint in the mixer code, which passes through its sources' hints since #831. Reproduce by running the snippet from the issue in a debug build with a Zero source. Done means no overflow panic for unbounded sources and a sensible size hint, such as (0, None), that the maintainers agree on.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

During development on the Zed codebase, I ran into a crash related to rodio. Below is what I was able to gather about the problem. Disclaimer: I am not very familiar with Rust and the code base and used AI help to arrive at this diagnosis (this report is still written by me though).

What I observed

ChannelCountConverter::size_hint panics when its source is unbounded (e.g. Zero). The converter does arithmetic on the size hint returned by the underlying source and if that size hint is (usize::MAX, None) we get a panic due to arithmetic overflow at https://github.com/RustAudio/rodio/blob/685e05765c2aff8fbb51e32cda5b18428d09ffbe/src/conversions/channels.rs#L94-L99

Reproducing example

Run the following code in a debug build (release builds don't panic but will silently report a wrong size hint).

let (mixer, source) = rodio::mixer::mixer(nz!(2), nz!(48000));
mixer.add(rodio::source::Zero::new(nz!(1), nz!(48000))); // mono into stereo
let mut source = source;
assert!(source.next().is_some());
let _ = source.size_hint(); // panics: attempt to add with overflow

The core issue seems to affect multiple versions, but in practice the MixerSource was probably able to hide this issue in the past. The MixerSource returned a (0, None) size hint (I checked versions v0.22.2 and v0.23.0), which doesn't cause an overflow. #831 introduced a change causing the mixer to pass-through the size hint of its underlying sources. If the source is Zero (like in the reproduction above), we get a panic. This currently affects master (685e0576).

This behavior can also be observed in 3ee9745 (which is the commit pinned by Zed, which led me to create this issue).

Suggested fix

I'm not familiar enough with the code base to identify the best way to fix this. To me the following seems plausible:

  • Fix the ChannelCountConverter::size_hint implementation to gracefully handle infinite sources
  • Change MixerSource::size_hint to return (0, None) for infinite sources to prevent other consumers from panicking when doing arithmetic on size hints when infinite sources are involved. This is its behavior in v0.22.2 and v0.23.0.

Related

#609 reported the sibling subtract overflow in the same function
#698 additionally suspected delay's size_hint

Ngôn ngữ chính
Rust
Star
2.5k
Fork
338
Merge trung bình
1 ngày 3 giờ
Pull request đã merge (30 ngày)
1

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của RustAudio/rodio

Tất cả issue của RustAudio/rodio

Issue tương tự

Thêm issue về Rust

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.