`size_hint` overflow panic for unbounded source

オープン
#935 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
3/5
見積もり時間
半日
初心者へのやさしさ
58/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
活発
技術スタック
rust

調査の方向性

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.

索引モデルが issue の本文から書いたものです。

説明

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

主要言語
Rust
スター
2.5k
フォーク
338
平均マージ
1日 3時間
マージ済み PR(30日)
1

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

RustAudio/rodio のほかの issue

RustAudio/rodio の issue をすべて見る

似ている issue

Rust の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。