1 Description: fix buffer overflow when changing both sample format and
3 Origin: https://github.com/mpruett/audiofile/pull/25
4 Bug-Ubuntu: https://bugs.launchpad.net/ubuntu/+source/audiofile/+bug/1502721
5 Bug-Debian: https://bugs.debian.org/801102
7 --- a/libaudiofile/modules/ModuleState.cpp
8 +++ b/libaudiofile/modules/ModuleState.cpp
9 @@ -402,7 +402,7 @@ status ModuleState::arrange(AFfilehandle
10 addModule(new Transform(outfc, in.pcm, out.pcm));
12 if (in.channelCount != out.channelCount)
13 - addModule(new ApplyChannelMatrix(infc, isReading,
14 + addModule(new ApplyChannelMatrix(outfc, isReading,
15 in.channelCount, out.channelCount,
16 in.pcm.minClip, in.pcm.maxClip,
17 track->channelMatrix));
18 --- a/test/Makefile.am
19 +++ b/test/Makefile.am
20 @@ -26,6 +26,7 @@ TESTS = \
24 + sixteen-stereo-to-eight-mono \
28 @@ -139,6 +140,7 @@ printmarkers_SOURCES = printmarkers.c
29 printmarkers_LDADD = $(LIBAUDIOFILE) -lm
31 sixteen_to_eight_SOURCES = sixteen-to-eight.c TestUtilities.cpp TestUtilities.h
32 +sixteen_stereo_to_eight_mono_SOURCES = sixteen-stereo-to-eight-mono.c TestUtilities.cpp TestUtilities.h
34 testchannelmatrix_SOURCES = testchannelmatrix.c TestUtilities.cpp TestUtilities.h
37 +++ b/test/sixteen-stereo-to-eight-mono.c
42 + Copyright 2000, Silicon Graphics, Inc.
44 + This program is free software; you can redistribute it and/or modify
45 + it under the terms of the GNU General Public License as published by
46 + the Free Software Foundation; either version 2 of the License, or
47 + (at your option) any later version.
49 + This program is distributed in the hope that it will be useful,
50 + but WITHOUT ANY WARRANTY; without even the implied warranty of
51 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
52 + GNU General Public License for more details.
54 + You should have received a copy of the GNU General Public License along
55 + with this program; if not, write to the Free Software Foundation, Inc.,
56 + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
60 + sixteen-stereo-to-eight-mono.c
62 + This program tests the conversion from 2-channel 16-bit integers to
63 + 1-channel 8-bit integers.
77 +#include <audiofile.h>
79 +#include "TestUtilities.h"
81 +int main (int argc, char **argv)
85 + int16_t frames16[] = {14298, 392, 3923, -683, 958, -1921};
86 + int8_t frames8[] = {28, 6, -2};
87 + int i, frameCount = 3;
89 + AFframecount result;
91 + setup = afNewFileSetup();
93 + afInitFileFormat(setup, AF_FILE_WAVE);
95 + afInitSampleFormat(setup, AF_DEFAULT_TRACK, AF_SAMPFMT_TWOSCOMP, 16);
96 + afInitChannels(setup, AF_DEFAULT_TRACK, 2);
99 + if (!createTemporaryFile("sixteen-to-eight", &testFileName))
101 + fprintf(stderr, "Could not create temporary file.\n");
102 + exit(EXIT_FAILURE);
105 + file = afOpenFile(testFileName, "w", setup);
106 + if (file == AF_NULL_FILEHANDLE)
108 + fprintf(stderr, "could not open file for writing\n");
109 + exit(EXIT_FAILURE);
112 + afFreeFileSetup(setup);
114 + afWriteFrames(file, AF_DEFAULT_TRACK, frames16, frameCount);
118 + file = afOpenFile(testFileName, "r", AF_NULL_FILESETUP);
119 + if (file == AF_NULL_FILEHANDLE)
121 + fprintf(stderr, "could not open file for reading\n");
122 + exit(EXIT_FAILURE);
125 + afSetVirtualSampleFormat(file, AF_DEFAULT_TRACK, AF_SAMPFMT_TWOSCOMP, 8);
126 + afSetVirtualChannels(file, AF_DEFAULT_TRACK, 1);
128 + for (i=0; i<frameCount; i++)
130 + /* Read one frame. */
131 + result = afReadFrames(file, AF_DEFAULT_TRACK, &byte, 1);
136 + /* Compare the byte read with its precalculated value. */
137 + if (memcmp(&byte, &frames8[i], 1) != 0)
140 + printf("expected %d, got %d\n", frames8[i], byte);
141 + exit(EXIT_FAILURE);
146 + printf("got what was expected: %d\n", byte);
152 + unlink(testFileName);
153 + free(testFileName);
155 + exit(EXIT_SUCCESS);