diff --git a/extractaudio/decoder.c b/extractaudio/decoder.c index d3c3ca17a..27647acea 100644 --- a/extractaudio/decoder.c +++ b/extractaudio/decoder.c @@ -242,7 +242,7 @@ decode_frame(struct decoder_stream *dp, int16_t *obuf, unsigned char *ibuf, if (ibytes < 33) { return (-1); } - for (obytes = 0; ibytes > 0 && obytes <= obytes_max - 320; ibytes -= 33) { + for (obytes = 0; ibytes >= 33 && obytes <= obytes_max - 320; ibytes -= 33) { gsm_decode(dp->ctx_gsm, ibuf, obuf); ibuf += 33; obuf += 160; diff --git a/tests/Makefile.in b/tests/Makefile.in index 1f4cb349e..4d88f5c45 100644 --- a/tests/Makefile.in +++ b/tests/Makefile.in @@ -112,6 +112,7 @@ host_triplet = @host@ @ENABLE_BASIC_TESTS_TRUE@ extractaudio/extractaudio1 \ @ENABLE_BASIC_TESTS_TRUE@ extractaudio/scan \ @ENABLE_BASIC_TESTS_TRUE@ extractaudio/encopts \ +@ENABLE_BASIC_TESTS_TRUE@ extractaudio/gsm_partial \ @ENABLE_BASIC_TESTS_TRUE@ startstop/goodargs startstop/badargs \ @ENABLE_BASIC_TESTS_TRUE@ startstop/startstop1 \ @ENABLE_BASIC_TESTS_TRUE@ startstop/nodebug \ @@ -438,7 +439,8 @@ EXTRA_DIST = $(am__append_3) $(am__append_5) $(am__append_9) \ @ENABLE_BASIC_TESTS_TRUE@ *.mono.*.rlog *.stereo.*.rlog *.scan.rlog *.scan.tout \ @ENABLE_BASIC_TESTS_TRUE@ *.stereo.*.raw *.stereo.*.raw.tout *.nbcheck.*.raw.txt \ @ENABLE_BASIC_TESTS_TRUE@ *.encopts.*.ogg *.encopts.*.ogg.tout *.encopts.*.ogg.rlog \ -@ENABLE_BASIC_TESTS_TRUE@ encopts.probe.ogg badargs.clevel.wav badargs.out.ogg +@ENABLE_BASIC_TESTS_TRUE@ encopts.probe.ogg badargs.clevel.wav badargs.out.ogg \ +@ENABLE_BASIC_TESTS_TRUE@ gsm_partial.*.raw gsm_partial.*.raw.tout gsm_partial.*.raw.rlog @ENABLE_BASIC_TESTS_TRUE@startstop_EXTRA_DIST = startstop @ENABLE_BASIC_TESTS_TRUE@startstop_CLEANFILES = startstop*.rout startstop*.rlog diff --git a/tests/extractaudio/Makefile.ami b/tests/extractaudio/Makefile.ami index 2d44fa391..5c1786064 100644 --- a/tests/extractaudio/Makefile.ami +++ b/tests/extractaudio/Makefile.ami @@ -5,8 +5,9 @@ extractaudio_CLEANFILES = *.mono.*.wav *.stereo.*.wav *.mono.*.wav.tout \ *.mono.*.rlog *.stereo.*.rlog *.scan.rlog *.scan.tout \ *.stereo.*.raw *.stereo.*.raw.tout *.nbcheck.*.raw.txt \ *.encopts.*.ogg *.encopts.*.ogg.tout *.encopts.*.ogg.rlog \ - encopts.probe.ogg badargs.clevel.wav badargs.out.ogg + encopts.probe.ogg badargs.clevel.wav badargs.out.ogg \ + gsm_partial.*.raw gsm_partial.*.raw.tout gsm_partial.*.raw.rlog TESTS += extractaudio/badargs extractaudio/extractaudio1 extractaudio/scan \ - extractaudio/encopts + extractaudio/encopts extractaudio/gsm_partial CLEANFILES += ${extractaudio_CLEANFILES} EXTRA_DIST += ${extractaudio_EXTRA_DIST} diff --git a/tests/extractaudio/corrupted_gsm.a.rtp b/tests/extractaudio/corrupted_gsm.a.rtp new file mode 100644 index 000000000..995804bd8 Binary files /dev/null and b/tests/extractaudio/corrupted_gsm.a.rtp differ diff --git a/tests/extractaudio/corrupted_gsm.o.rtp b/tests/extractaudio/corrupted_gsm.o.rtp new file mode 100644 index 000000000..d7c6ccd12 Binary files /dev/null and b/tests/extractaudio/corrupted_gsm.o.rtp differ diff --git a/tests/extractaudio/gsm_partial b/tests/extractaudio/gsm_partial new file mode 100755 index 000000000..17b53e275 --- /dev/null +++ b/tests/extractaudio/gsm_partial @@ -0,0 +1,26 @@ +#!/bin/sh + +# A GSM packet whose payload is not a multiple of 33 bytes has to be decoded +# up to the last whole frame, the trailing remainder has to be ignored. +# +# corrupted_gsm is call1_gsm with an extra byte appended to some of the +# packets (34 byte payload), so the decoded audio has to match that of the +# original recording exactly. Before the fix the decoder went on past the end +# of the packet, producing garbage and reading out of bounds. + +BASEDIR="`dirname "${0}"`/.." +. "${BASEDIR}/functions" + +for rname in call1_gsm corrupted_gsm +do + wfile="gsm_partial.${rname}.raw" + rm -f "${wfile}" + ${EXTRACTAUDIO} -F raw -D pcm_16 "${BASEDIR}/extractaudio/${rname}" \ + "${wfile}" 2>"${wfile}.rlog" >"${wfile}.tout" + report "${EXTRACTAUDIO} ${rname} -> ${wfile}" + test -s "${wfile}" + report "checking that ${wfile} is not empty" +done + +cmp gsm_partial.call1_gsm.raw gsm_partial.corrupted_gsm.raw +report "checking that corrupted_gsm decodes the same as call1_gsm"