Skip to content

silently discard trailing partial sample byte#100

Open
JaySon-Huang wants to merge 1 commit into
ruuda:releasefrom
JaySon-Huang:tolerate_trailing_chunk
Open

silently discard trailing partial sample byte#100
JaySon-Huang wants to merge 1 commit into
ruuda:releasefrom
JaySon-Huang:tolerate_trailing_chunk

Conversation

@JaySon-Huang
Copy link
Copy Markdown

Problem

close #63, close #81

WavReader::new() currently rejects WAV files where data_len % bytes_per_sample != 0, returning an Error::FormatError ("data chunk length is not a multiple of sample size").

However, real-world audio files often have a missing final byte from truncated transfers, and mainstream players (VLC, ffmpeg, Symphonia) handle them gracefully by ignoring the trailing byte(s).

Why the change is safe

  • num_samples is computed via integer division, which naturally discards the partial trailing sample.
  • WavReader only uses num_samples for subsequent reads — the truncated data_len is never referenced again.

Verification

Tested against 7 real-world truncated WAV files that previously failed:

All 7 files now decode successfully with the patch, producing the expected sample counts (last partial sample silently dropped). 88 non-truncated control files continue to decode identically.

Signed-off-by: JaySon-Huang <tshent@qq.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.

hound errors out when trying to read samples from this file Getting error "data chunk length is not a multiple of sample size" for some files

1 participant