Monday, April 03, 2023

audio/sox unbreak wav gsm

wav gsm playback and encoding is broken because the wav.c patch to avoid
division by 0 introduced a regression. Debian has a fix for an older
version of sox from Helmut Grohne <helmut () subdivi ! de>. This patch
is from Steffen Nurpmeso <steffen () sdaoden ! eu> who applied it
against git. I added a tweak to not recalculate wave->numSamples for wav
gsm files, which is where division by 0 happens. Apparently, gsm has
variable bits_per_sample, so 0 is an acceptable value.

Steffen's diff: https://marc.info/?l=oss-security&m=167882517702862&w=2
tweak: https://marc.info/?l=oss-security&m=168026419507884&w=2

Test cases
----------
With this diff these two test cases pass.

Test case 1: convert /dev/null to bug.wav (wav gsm) and then convert
bug.wav to fail.wav.

This test case is expected to pass.

incorrect output:
--8<---------------cut here---------------start------------->8---
$ sox -t raw -r 44100 -e signed-integer -b 8 /dev/null -t wav -e gsm-full-rate \
bug.wav $ sox bug.wav fail.wav
sox FAIL formats: can't open input file `bug.wav': WAV file bits per sample is zero
--8<---------------cut here---------------end--------------->8---

correct output (which this provides):
--8<---------------cut here---------------start------------->8---
$ sox -t raw -r 44100 -e signed-integer -b 8 /dev/null -t wav -e gsm-full-rate \
bug.wav $ sox bug.wav fail.wav
$ file fail.wav
fail.wav: RIFF (little-endian) data, WAVE audio, GSM 6.10, mono 44100 Hz
--8<---------------cut here---------------end--------------->8---

Test case 2: convert flac to wav gsm. then, convert wav gsm to wav gsm.

This test case is expected to pass.
--8<---------------cut here---------------start------------->8---
$ sox -t flac -r 44100 -e signed-integer -b 16 song.flac -t wav -e gsm-full-rate \
ok.wav $ sox ok.wav ok2.wav
--8<---------------cut here---------------end--------------->8---

Feedback is welcome. OK?

Index: Makefile
===================================================================
RCS file: /cvs/ports/audio/sox/Makefile,v
retrieving revision 1.76
diff -u -p -u -p -r1.76 Makefile
--- Makefile 22 Feb 2023 16:27:38 -0000 1.76
+++ Makefile 3 Apr 2023 22:51:32 -0000
@@ -5,7 +5,7 @@ V= 14.4.2pl20210509
GIT_V= 14.4.3git
DISTNAME= sox-${V}
SHARED_LIBS += sox 4.1 # 3.0
-REVISION= 0
+REVISION= 1

CATEGORIES= audio
HOMEPAGE= http://sox.sourceforge.net/
Index: patches/patch-src_wav_c
===================================================================
RCS file: /cvs/ports/audio/sox/patches/patch-src_wav_c,v
retrieving revision 1.3
diff -u -p -u -p -r1.3 patch-src_wav_c
--- patches/patch-src_wav_c 22 Feb 2023 15:03:03 -0000 1.3
+++ patches/patch-src_wav_c 3 Apr 2023 22:51:32 -0000
@@ -1,14 +1,22 @@
https://marc.info/?l=oss-security&m=167571683504082&w=2

+unbreak wav gsm
+see:
+https://marc.info/?l=oss-security&m=167882517702862&w=2
+https://marc.info/?l=oss-security&m=168026419507884&w=2
+
Index: src/wav.c
--- src/wav.c.orig
+++ src/wav.c
-@@ -654,6 +654,12 @@ static int wav_read_fmt(sox_format_t *ft, uint32_t len
+@@ -654,6 +654,15 @@ static int wav_read_fmt(sox_format_t *ft, uint32_t len
if (err)
return SOX_EOF;

-+ if (wav->bitsPerSample == 0)
-+ {
++ if (wav->bitsPerSample == 0
++#ifdef HAVE_LIBGSM
++ && wav->formatTag != WAVE_FORMAT_GSM610
++

No comments:

Post a Comment