voc: fix division by zero when v->size is zero #264
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "openclaw-dev/sox_ng:fix/division-by-zero-voc"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Problem Background
Issue #247 reports a division by zero crash in the VOC audio format reader (src/voc.c). This was discovered by fuzzing torchaudio with sydr-fuzz.
The original report (SourceForge patch 127) noted that division by v->size occurs without necessary checking.
Root Cause
In read_samples_voc() (src/voc.c), line 344 performs:
size_t per = max(1, 9 / v->size);When v->size == 0 (which can occur when a malformed VOC file causes the format byte not to map to a valid size), this triggers undefined behavior / crash.
A pre-existing check at line 335 catches v->size == 0 but uses lsx_warn() followed by return 0 - returning success (0) instead of an error. This means sox_ng exits with status 0 even when the file is corrupt.
Fix
Replace lsx_warn() with lsx_fail_errno(ft, SOX_EFMT, ...):
This matches the pattern used by other error conditions in voc.c (e.g., lines 367, 604, 631, 640) and ensures the error is properly surfaced and sox_ng exits with a non-zero status code.
Key Changes
Verification
Many thanks.
Merged into mainline as https://codeberg.org/sox_ng/sox_ng/commit/10f762
Blessings
MPull request closed