aboutsummaryrefslogtreecommitdiff
Description: fix buffer overflow when changing both sample format and
 number of channels
Origin: https://github.com/mpruett/audiofile/pull/25
Bug-Ubuntu: https://bugs.launchpad.net/ubuntu/+source/audiofile/+bug/1502721
Bug-Debian: https://bugs.debian.org/801102

--- a/libaudiofile/modules/ModuleState.cpp
+++ b/libaudiofile/modules/ModuleState.cpp
@@ -402,7 +402,7 @@ status ModuleState::arrange(AFfilehandle
 		addModule(new Transform(outfc, in.pcm, out.pcm));
 
 	if (in.channelCount != out.channelCount)
-		addModule(new ApplyChannelMatrix(infc, isReading,
+		addModule(new ApplyChannelMatrix(outfc, isReading,
 			in.channelCount, out.channelCount,
 			in.pcm.minClip, in.pcm.maxClip,
 			track->channelMatrix));
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -26,6 +26,7 @@ TESTS = \
 	VirtualFile \
 	floatto24 \
 	query2 \
+	sixteen-stereo-to-eight-mono \
 	sixteen-to-eight \
 	testchannelmatrix \
 	testdouble \
@@ -139,6 +140,7 @@ printmarkers_SOURCES = printmarkers.c
 printmarkers_LDADD = $(LIBAUDIOFILE) -lm
 
 sixteen_to_eight_SOURCES = sixteen-to-eight.c TestUtilities.cpp TestUtilities.h
+sixteen_stereo_to_eight_mono_SOURCES = sixteen-stereo-to-eight-mono.c TestUtilities.cpp TestUtilities.h
 
 testchannelmatrix_SOURCES = testchannelmatrix.c TestUtilities.cpp TestUtilities.h
 
--- /dev/null
+++ b/test/sixteen-stereo-to-eight-mono.c
@@ -0,0 +1,118 @@
+/*
+	Audio File Library
+
+	Copyright 2000, Silicon Graphics, Inc.
+
+	This program is free software; you can redistribute it and/or modify
+	it under the terms of the GNU General Public License as published by
+	the Free Software Foundation; either version 2 of the License, or
+	(at your option) any later version.
+
+	This program is distributed in the hope that it will be useful,
+	but WITHOUT ANY WARRANTY; without even the implied warranty of
+	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+	GNU General Public License for more details.
+
+	You should have received a copy of the GNU General Public License along
+	with this program; if not, write to the Free Software Foundation, Inc.,
+	51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+*/
+
+/*
+	sixteen-stereo-to-eight-mono.c
+
+	This program tests the conversion from 2-channel 16-bit integers to
+	1-channel 8-bit	integers.
+*/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <limits.h>
+
+#include <audiofile.h>
+
+#include "TestUtilities.h"
+
+int main (int argc, char **argv)
+{
+	AFfilehandle file;
+	AFfilesetup setup;
+	int16_t frames16[] = {14298, 392, 3923, -683, 958, -1921};
+	int8_t frames8[] = {28, 6, -2};
+	int i, frameCount = 3;
+	int8_t byte;
+	AFframecount result;
+
+	setup = afNewFileSetup();
+
+	afInitFileFormat(setup, AF_FILE_WAVE);
+
+	afInitSampleFormat(setup, AF_DEFAULT_TRACK, AF_SAMPFMT_TWOSCOMP, 16);
+	afInitChannels(setup, AF_DEFAULT_TRACK, 2);
+
+	char *testFileName;
+	if (!createTemporaryFile("sixteen-to-eight", &testFileName))
+	{
+		fprintf(stderr, "Could not create temporary file.\n");
+		exit(EXIT_FAILURE);
+	}
+
+	file = afOpenFile(testFileName, "w", setup);
+	if (file == AF_NULL_FILEHANDLE)
+	{
+		fprintf(stderr, "could not open file for writing\n");
+		exit(EXIT_FAILURE);
+	}
+
+	afFreeFileSetup(setup);
+
+	afWriteFrames(file, AF_DEFAULT_TRACK, frames16, frameCount);
+
+	afCloseFile(file);
+
+	file = afOpenFile(testFileName, "r", AF_NULL_FILESETUP);
+	if (file == AF_NULL_FILEHANDLE)
+	{
+		fprintf(stderr, "could not open file for reading\n");
+		exit(EXIT_FAILURE);
+	}
+
+	afSetVirtualSampleFormat(file, AF_DEFAULT_TRACK, AF_SAMPFMT_TWOSCOMP, 8);
+	afSetVirtualChannels(file, AF_DEFAULT_TRACK, 1);
+
+	for (i=0; i<frameCount; i++)
+	{
+		/* Read one frame. */
+		result = afReadFrames(file, AF_DEFAULT_TRACK, &byte, 1);
+
+		if (result != 1)
+			break;
+
+		/* Compare the byte read with its precalculated value. */
+		if (memcmp(&byte, &frames8[i], 1) != 0)
+		{
+			printf("error\n");
+			printf("expected %d, got %d\n", frames8[i], byte);
+			exit(EXIT_FAILURE);
+		}
+		else
+		{
+#ifdef DEBUG
+			printf("got what was expected: %d\n", byte);
+#endif
+		}
+	}
+
+	afCloseFile(file);
+	unlink(testFileName);
+	free(testFileName);
+
+	exit(EXIT_SUCCESS);
+}
oltip'>* gnu/system/vm.scm (qemu-image): Import missing (gnu build hurd-boot) module. Signed-off-by: Maxim Cournoyer <maxim.cournoyer@gmail.com> Royce Strange 2020-06-08hurd-boot: Further cleanup of "rc"....* gnu/packages/hurd.scm (hurd-rc-script): Move implementation to ... * gnu/build/hurd-boot.scm (boot-hurd-system): ...here, new file. * gnu/build/linux-boot.scm (make-hurd-device-nodes): Move there likewise. * gnu/local.mk (GNU_SYSTEM_MODULES): Add it. Jan (janneke) Nieuwenhuizen 2020-06-06vm: Shared-store script runs the native QEMU and Bash....* gnu/system/vm.scm (system-qemu-image/shared-store-script): Use #+ for QEMU and BASH. Ludovic Courtès 2020-06-06vm: <virtual-machine> compiler honors system and target....* gnu/system/vm.scm (system-qemu-image/shared-store): Add #:system and #:target. Pass it down. (system-qemu-image/shared-store-script): Likewise. (virtual-machine-compiler): Likewise. Ludovic Courtès 2020-06-06vm: 'qemu-image' preserves the cross-compilation target of the OS....* gnu/system/vm.scm (qemu-image)[preserve-target, inputs*]: New variables. In gexp, use INPUTS* instead of INPUTS. Wrap OS and BOOTCFG-DRV in 'preserve-target'. Pass INPUTS* instead of INPUTS as the #:references-graphs. Ludovic Courtès 2020-06-06vm: 'qemu-image' uses the native partitioning tools and bootloader....* gnu/system/vm.scm (qemu-image): Use #+ for Parted, the bootloader, etc. Ludovic Courtès 2020-06-06vm: 'expression->derivation-in-linux-vm' always returns a native build....* gnu/system/vm.scm (expression->derivation-in-linux-vm): Remove #:target. [builder]: Use #+. Don't pass #:target-arm32? and #:target-aarch64? to 'load-in-linux-vm'. Pass #:target #f to 'gexp->derivation'. (qemu-image): Adjust accordingly. * gnu/build/vm.scm (load-in-linux-vm): Remove #:target-aarch64? and #:target-arm32?. Define them as local variables. Ludovic Courtès 2020-05-16vm: Use 'let-system'....* gnu/system/vm.scm (expression->derivation-in-linux-vm)[check]: New macro. [builder]: Use 'let-system' and 'check' instead of referencing '%current-system' and '%current-target-system'. Ludovic Courtès 2020-05-08Merge branch 'core-updates'Marius Bakke 2020-05-07guix system: 'docker-image' honors '--network'....* gnu/system/vm.scm (system-docker-image): Add #:shared-network? and pass it to 'containerized-operating-system'. (qemu-image): * guix/scripts/system.scm (system-derivation-for-action): Pass #:shared-network? to 'system-docker-image'. * doc/guix.texi (Invoking guix system): Document it. Ludovic Courtès 2020-05-05Merge branch 'master' into core-updatesMarius Bakke 2020-05-05vm: Remove obsolete procedures....* gnu/build/vm.scm (install-efi, make-iso9660-image): Remove those procedures that are now implemented in (gnu build image) module, (initialize-hard-disk): remove efi support. * gnu/system/vm.scm (iso9660-image): Remove it, (qemu-image): adapt it to remove ISO9660 support. Mathieu Othacehe 2020-05-05image: Add a new API....Raw disk-images and ISO9660 images are created in a Qemu virtual machine. This is quite fragile, very slow, and almost unusable without KVM. For all these reasons, add support for host image generation. This implies the use new image generation mechanisms. - Raw disk images: images of partitions are created using tools such as mke2fs and mkdosfs depending on the partition file-system type. The partition images are then assembled into a final image using genimage. - ISO9660 images: the ISO root directory is populated within the store. GNU xorriso is then called on that directory, in the exact same way as this is done in (gnu build vm) module. Those mechanisms are built upon the new (gnu image) module. * gnu/image.scm: New file. * gnu/system/image.scm: New file. * gnu/build/image: New file. * gnu/local.mk: Add them. * gnu/system/vm.scm (system-disk-image): Rename to system-disk-image-in-vm. * gnu/ci.scm (qemu-jobs): Adapt to new API. * gnu/tests/install.scm (run-install): Ditto. * guix/scripts/system.scm (system-derivation-for-action): Ditto. Mathieu Othacehe 2020-05-05system: vm: Move operating-system-uuid....* gnu/system/vm.scm (operating-system-uuid): Move to ... * gnu/system.scm: ... here. Mathieu Othacehe 2020-04-26Merge branch 'master' into core-updatesMarius Bakke 2020-04-26vm: Remove unused import....* gnu/system/vm.scm: Do not import (gnu packages make-bootstrap). Marius Bakke 2020-04-11vm: Make the device node procedure a parameter....* gnu/build/vm.scm (root-partition-initializer): Add #:make-device-nodes parameter and use it. * gnu/system/vm.scm (qemu-image): Add #:device-node parameter. Pass #:make-device-nodes to 'root-partition-initializer'. Ludovic Courtès 2020-04-11vm: 'qemu-image' can pass options to the 'mkfs' command....* gnu/build/vm.scm (<partition>)[file-system-options]: New field. (create-ext-file-system, create-fat-file-system) (format-partition): Add #:options and honor it. (initialize-partition): Pass #:options to 'format-partition'. * gnu/system/vm.scm (qemu-image): Add #:file-system-options and use it for the root partition. Ludovic Courtès 2020-04-11vm: 'qemu-image' accepts a list of extra populate directives....* gnu/build/vm.scm (root-partition-initializer): Add #:extra-directives parameter and pass it to 'populate-root-file-system'. * gnu/system/vm.scm (qemu-image): Add #:extra-directives parameter and pass it to 'root-partition-initializer'. Ludovic Courtès 2020-04-10vm: Use virtio network driver....This fixes a regression introduced in 8e53fe2b91d2776bc1529e7b34967c8f1d9edc32 where 'guix system vm' would no longer be using virtio. * gnu/system/vm.scm (common-qemu-options): Add "-nic user,model=virtio-net-pci". Marius Bakke 2020-04-10vm: 'system-disk-image' honors #:substitutable? for ISO9660 images....This is a followup to a328f66a9e16d7bae765d8bc088e4a97037e6e2b. * gnu/system/vm.scm (iso9660-image): Add #:substitutable? and pass it to 'expression->derivation-in-linux-vm'. (system-disk-image): Pass #:substitutable? to 'iso9660-image'. Ludovic Courtès 2020-04-08vm: Allow images to be marked as non-substitutable....* gnu/system/vm.scm (expression->derivation-in-linux-vm): Add #:substitutable? parameter. Pass it to 'gexp->derivation'. (qemu-image): Add #:substitutable? and pass it to 'expression->derivation-in-linux-vm'. (system-disk-image): Add #:substitutable? and pass it to 'qemu-image'. Ludovic Courtès 2020-03-26vm: Distinguish between success and failure of the guest code....Fixes <https://bugs.gnu.org/34276>. Reported by Tobias Geerinckx-Rice <me@tobias.gr>. * gnu/system/vm.scm (expression->derivation-in-linux-vm)[loader]: Produce '/xchg/.exit-status' file upon success. * gnu/build/vm.scm (load-in-linux-vm): Check for 'xchg/.exit-status' once QEMU has completed and respond accordingly. Ludovic Courtès 2020-03-10vm: Compute UUIDs truly deterministically....This is a followup to 1540075c790dfaeff52c93392f2fc63b9e23b77e. The mistake had no effect on prior Guile versions but it's visible since Guile 3.0.1 and the fix for <https://bugs.gnu.org/39634>. * gnu/system/vm.scm (operating-system-uuid): Hash a list of 'file-system-digest' values, not the 'file-system-type' procedure. Ludovic Courtès 2020-03-02file-systems: Add a 'file-system-device->string' procedure....* gnu/system/file-systems.scm (file-system-device->string): New procedure. * gnu/system.scm (bootable-kernel-arguments): Use it. * gnu/system/vm.scm (operating-system-uuid): Likewise. * guix/scripts/system.scm (display-system-generation): Likewise. Maxim Cournoyer 2019-12-18gnu: Remove uses of deprecated Qemu network configuration....* gnu/build/vm.scm (load-in-linux-vm): Move Qemu network configuration from ARCH-SPECIFIC-FLAGS to the Qemu command line. Use the "-nic" option of Qemu instead of "-device" and "-net". * gnu/system/vm.scm (common-qemu-options): Do not add a '-net' command. (virtual-machine-compiler): Use "-nic user,..." instead of "-net". * doc/guix.texi (Installing Guix in a VM, Invoking guix system, Running Guix in a VM): Do the same for examples. Marius Bakke 2019-12-01system: vm: Support cross-compilation....* gnu/system.scm (system-linux-image-file-name): Add support for cross-built systems. Remove system argument that was ignored, (operating-system-kernel-file): adapt by removing ignored os argument. * gnu/system/vm.scm (expression->derivation-in-linux-vm): Add target argument and turn inputs into native-inputs. Pass target to qemu-command and gexp->derivation calls. (iso9660-image): Add target argument and pass it to expression->derivation-in-linux-vm. Remove qemu from inputs as it is not necessary. (qemu-image): Add target argument, also remove qemu from inputs. Pass target argument to expression->derivation-in-linux-vm call. Mathieu Othacehe 2019-11-22system: vm: Add arm64 support....* gnu/build/vm.scm (load-in-linux-vm): Add target-arm64? argument and use it to pass correct arguments to qemu. * gnu/system/vm.scm (expression->derivation-in-linux-vm): Pass the new target-arm64? argument added above. Do not add ESP partition on all ARM targets. Do not pass grub-efi package to initialize-hard-disk on ARM targets. Mathieu Othacehe 2019-11-18vm: Honor the VOLATILE? parameter when producing a system disk image....* gnu/system/vm.scm (system-disk-image): Honor the VOLATILE? parameter instead of hard coding its value to #t. Reported-by: Jelle Licht <jlicht@fsfe.org> Maxim Cournoyer