Skip to content

fix(media): skip the RIFF pad byte after odd-sized WAV chunks - #315

Merged
yeoleobun merged 1 commit into
restsend:mainfrom
imeerkhurram:fix/wav-chunk-padding
Dec 1, 2026
Merged

yeoleobun merged 1 commit into
restsend:mainfrom
imeerkhurram:fix/wav-chunk-padding

Conversation

@imeerkhurram

Copy link
Copy Markdown
Contributor

WavReader moves past a chunk by exactly its declared size. RIFF chunks are word-aligned, so an odd-sized chunk is followed by a pad byte that the size doesn't count. One such chunk before data shifts the rest of the walk by a byte and the file is rejected with No data chunk found in WAV file: FileAudioSource::new fails, and estimate_audio_duration falls back to 5 s. load_wav_pcm16 (hold music) already rounds the size up, so the same file works there.

Example, with a 627-byte bext chunk:

ffmpeg -f lavfi -i sine=frequency=440:duration=0.5:sample_rate=8000 -ac 1 -c:a pcm_s16le \
  -write_bext 1 -metadata coding_history="A=PCM,F=8000,W=16,M=mono" prompt.wav

Before: the error above. After: 4000 samples, 500 ms.

The byte is only consumed when it is there (zero), so files written without it, which the reader accepts today (test_list_and_fact_chunks), still parse.

Two new tests fail without the change. cargo test -p rustpbx-media --lib: 457 passed, 9 ignored. cargo test --workspace --lib: 3138 passed. e2e_core: 578 passed, with RUST_MIN_STACK=67108864, because the debug build aborts on my Mac without it (on main too).

WavReader moved on by exactly the declared chunk size, so one odd-sized
chunk before the data chunk shifted the rest of the walk by a byte and the
file was rejected with "No data chunk found in WAV file".
@yeoleobun
yeoleobun merged commit d29013b into restsend:main Dec 1, 2026
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.

2 participants