1Description: fix buffer overflow when changing both sample format and
2 number of channels
3Origin: backport, https://github.com/mpruett/audiofile/pull/25
4Bug-Ubuntu: https://bugs.launchpad.net/ubuntu/+source/audiofile/+bug/1502721
5Bug-Debian: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=801102
6
7Index: audiofile-0.3.6/libaudiofile/modules/ModuleState.cpp
8===================================================================
9--- audiofile-0.3.6.orig/libaudiofile/modules/ModuleState.cpp 2015-10-20 08:00:58.036128202 -0400
10+++ audiofile-0.3.6/libaudiofile/modules/ModuleState.cpp 2015-10-20 08:00:58.036128202 -0400
11@@ -402,7 +402,7 @@
12 addModule(new Transform(outfc, in.pcm, out.pcm));
13
14 if (in.channelCount != out.channelCount)
15- addModule(new ApplyChannelMatrix(infc, isReading,
16+ addModule(new ApplyChannelMatrix(outfc, isReading,
17 in.channelCount, out.channelCount,
18 in.pcm.minClip, in.pcm.maxClip,
19 track->channelMatrix));
20Index: audiofile-0.3.6/test/Makefile.am
21===================================================================
22--- audiofile-0.3.6.orig/test/Makefile.am 2015-10-20 08:00:58.036128202 -0400
23+++ audiofile-0.3.6/test/Makefile.am 2015-10-20 08:00:58.036128202 -0400
24@@ -26,6 +26,7 @@
25 VirtualFile \
26 floatto24 \
27 query2 \
28+ sixteen-stereo-to-eight-mono \
29 sixteen-to-eight \
30 testchannelmatrix \
31 testdouble \
32@@ -139,6 +140,7 @@
33 printmarkers_LDADD = $(LIBAUDIOFILE) -lm
34
35 sixteen_to_eight_SOURCES = sixteen-to-eight.c TestUtilities.cpp TestUtilities.h
36+sixteen_stereo_to_eight_mono_SOURCES = sixteen-stereo-to-eight-mono.c TestUtilities.cpp TestUtilities.h
37
38 testchannelmatrix_SOURCES = testchannelmatrix.c TestUtilities.cpp TestUtilities.h
39
40Index: audiofile-0.3.6/test/sixteen-stereo-to-eight-mono.c
41===================================================================
42--- /dev/null 1970-01-01 00:00:00.000000000 +0000
43+++ audiofile-0.3.6/test/sixteen-stereo-to-eight-mono.c 2015-10-20 08:33:57.512286416 -0400
44@@ -0,0 +1,117 @@
45+/*
46+ Audio File Library
47+
48+ Copyright 2000, Silicon Graphics, Inc.
49+
50+ This program is free software; you can redistribute it and/or modify
51+ it under the terms of the GNU General Public License as published by
52+ the Free Software Foundation; either version 2 of the License, or
53+ (at your option) any later version.
54+
55+ This program is distributed in the hope that it will be useful,
56+ but WITHOUT ANY WARRANTY; without even the implied warranty of
57+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
58+ GNU General Public License for more details.
59+
60+ You should have received a copy of the GNU General Public License along
61+ with this program; if not, write to the Free Software Foundation, Inc.,
62+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
63+*/
64+
65+/*
66+ sixteen-stereo-to-eight-mono.c
67+
68+ This program tests the conversion from 2-channel 16-bit integers to
69+ 1-channel 8-bit integers.
70+*/
71+
72+#ifdef HAVE_CONFIG_H
73+#include <config.h>
74+#endif
75+
76+#include <stdint.h>
77+#include <stdio.h>
78+#include <stdlib.h>
79+#include <string.h>
80+#include <unistd.h>
81+#include <limits.h>
82+
83+#include <audiofile.h>
84+
85+#include "TestUtilities.h"
86+
87+int main (int argc, char **argv)
88+{
89+ AFfilehandle file;
90+ AFfilesetup setup;
91+ int16_t frames16[] = {14298, 392, 3923, -683, 958, -1921};
92+ int8_t frames8[] = {28, 6, -2};
93+ int i, frameCount = 3;
94+ int8_t byte;
95+ AFframecount result;
96+
97+ setup = afNewFileSetup();
98+
99+ afInitFileFormat(setup, AF_FILE_WAVE);
100+
101+ afInitSampleFormat(setup, AF_DEFAULT_TRACK, AF_SAMPFMT_TWOSCOMP, 16);
102+ afInitChannels(setup, AF_DEFAULT_TRACK, 2);
103+
104+ char testFileName[PATH_MAX];
105+ if (!createTemporaryFile("sixteen-to-eight", testFileName))
106+ {
107+ fprintf(stderr, "Could not create temporary file.\n");
108+ exit(EXIT_FAILURE);
109+ }
110+
111+ file = afOpenFile(testFileName, "w", setup);
112+ if (file == AF_NULL_FILEHANDLE)
113+ {
114+ fprintf(stderr, "could not open file for writing\n");
115+ exit(EXIT_FAILURE);
116+ }
117+
118+ afFreeFileSetup(setup);
119+
120+ afWriteFrames(file, AF_DEFAULT_TRACK, frames16, frameCount);
121+
122+ afCloseFile(file);
123+
124+ file = afOpenFile(testFileName, "r", AF_NULL_FILESETUP);
125+ if (file == AF_NULL_FILEHANDLE)
126+ {
127+ fprintf(stderr, "could not open file for reading\n");
128+ exit(EXIT_FAILURE);
129+ }
130+
131+ afSetVirtualSampleFormat(file, AF_DEFAULT_TRACK, AF_SAMPFMT_TWOSCOMP, 8);
132+ afSetVirtualChannels(file, AF_DEFAULT_TRACK, 1);
133+
134+ for (i=0; i<frameCount; i++)
135+ {
136+ /* Read one frame. */
137+ result = afReadFrames(file, AF_DEFAULT_TRACK, &byte, 1);
138+
139+ if (result != 1)
140+ break;
141+
142+ /* Compare the byte read with its precalculated value. */
143+ if (memcmp(&byte, &frames8[i], 1) != 0)
144+ {
145+ printf("error\n");
146+ printf("expected %d, got %d\n", frames8[i], byte);
147+ exit(EXIT_FAILURE);
148+ }
149+ else
150+ {
151+#ifdef DEBUG
152+ printf("got what was expected: %d\n", byte);
153+#endif
154+ }
155+ }
156+
157+ afCloseFile(file);
158+ unlink(testFileName);
159+
160+ exit(EXIT_SUCCESS);
161+}