commit:     b8fc21b710b18e21dfba9506f666ec18744a3e64
Author:     Andreas Sturmlechner <asturm <AT> gentoo <DOT> org>
AuthorDate: Wed Oct  3 19:16:17 2018 +0000
Commit:     Andreas Sturmlechner <asturm <AT> gentoo <DOT> org>
CommitDate: Wed Oct  3 19:22:05 2018 +0000
URL:        https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=b8fc21b7

media-libs/libsndfile: Fix multiple vulnerabilities

Bug: https://bugs.gentoo.org/618016
Bug: https://bugs.gentoo.org/631634
Bug: https://bugs.gentoo.org/624814
Signed-off-by: Andreas Sturmlechner <asturm <AT> gentoo.org>
Package-Manager: Portage-2.3.50, Repoman-2.3.11

 .../files/libsndfile-1.0.28-CVE-2017-14634.patch   | 35 +++++++++++
 .../files/libsndfile-1.0.28-CVE-2017-6892.patch    | 25 ++++++++
 .../files/libsndfile-1.0.28-CVE-2017-8362.patch    | 50 ++++++++++++++++
 .../files/libsndfile-1.0.28-CVE-2017-8363.patch    | 28 +++++++++
 .../files/libsndfile-1.0.28-CVE-2017-8365.patch    | 64 ++++++++++++++++++++
 .../files/libsndfile-1.0.28-CVE-2018-13139.patch   |  2 +-
 media-libs/libsndfile/libsndfile-1.0.28-r4.ebuild  | 70 ++++++++++++++++++++++
 7 files changed, 273 insertions(+), 1 deletion(-)

diff --git a/media-libs/libsndfile/files/libsndfile-1.0.28-CVE-2017-14634.patch 
b/media-libs/libsndfile/files/libsndfile-1.0.28-CVE-2017-14634.patch
new file mode 100644
index 00000000000..9eab370aac4
--- /dev/null
+++ b/media-libs/libsndfile/files/libsndfile-1.0.28-CVE-2017-14634.patch
@@ -0,0 +1,35 @@
+From 85c877d5072866aadbe8ed0c3e0590fbb5e16788 Mon Sep 17 00:00:00 2001
+From: Fabian Greffrath <fab...@greffrath.com>
+Date: Thu, 28 Sep 2017 12:15:04 +0200
+Subject: [PATCH] double64_init: Check psf->sf.channels against upper bound
+
+This prevents division by zero later in the code.
+
+While the trivial case to catch this (i.e. sf.channels < 1) has already
+been covered, a crafted file may report a number of channels that is
+so high (i.e. > INT_MAX/sizeof(double)) that it "somehow" gets
+miscalculated to zero (if this makes sense) in the determination of the
+blockwidth. Since we only support a limited number of channels anyway,
+make sure to check here as well.
+
+CVE-2017-14634
+
+Closes: https://github.com/erikd/libsndfile/issues/318
+Signed-off-by: Erik de Castro Lopo <er...@mega-nerd.com>
+---
+ src/double64.c | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/src/double64.c b/src/double64.c
+index b318ea86..78dfef7f 100644
+--- a/src/double64.c
++++ b/src/double64.c
+@@ -91,7 +91,7 @@ int
+ double64_init (SF_PRIVATE *psf)
+ {     static int double64_caps ;
+ 
+-      if (psf->sf.channels < 1)
++      if (psf->sf.channels < 1 || psf->sf.channels > SF_MAX_CHANNELS)
+       {       psf_log_printf (psf, "double64_init : internal error : channels 
= %d\n", psf->sf.channels) ;
+               return SFE_INTERNAL ;
+               } ;

diff --git a/media-libs/libsndfile/files/libsndfile-1.0.28-CVE-2017-6892.patch 
b/media-libs/libsndfile/files/libsndfile-1.0.28-CVE-2017-6892.patch
new file mode 100644
index 00000000000..d5ccf726684
--- /dev/null
+++ b/media-libs/libsndfile/files/libsndfile-1.0.28-CVE-2017-6892.patch
@@ -0,0 +1,25 @@
+From f833c53cb596e9e1792949f762e0b33661822748 Mon Sep 17 00:00:00 2001
+From: Erik de Castro Lopo <er...@mega-nerd.com>
+Date: Tue, 23 May 2017 20:15:24 +1000
+Subject: [PATCH] src/aiff.c: Fix a buffer read overflow
+
+Secunia Advisory SA76717.
+
+Found by: Laurent Delosieres, Secunia Research at Flexera Software
+---
+ src/aiff.c | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/src/aiff.c b/src/aiff.c
+index 5b5f9f53..45864b76 100644
+--- a/src/aiff.c
++++ b/src/aiff.c
+@@ -1759,7 +1759,7 @@ aiff_read_chanmap (SF_PRIVATE * psf, unsigned dword)
+               psf_binheader_readf (psf, "j", dword - bytesread) ;
+ 
+       if (map_info->channel_map != NULL)
+-      {       size_t chanmap_size = psf->sf.channels * sizeof 
(psf->channel_map [0]) ;
++      {       size_t chanmap_size = SF_MIN (psf->sf.channels, layout_tag & 
0xffff) * sizeof (psf->channel_map [0]) ;
+ 
+               free (psf->channel_map) ;
+ 

diff --git a/media-libs/libsndfile/files/libsndfile-1.0.28-CVE-2017-8362.patch 
b/media-libs/libsndfile/files/libsndfile-1.0.28-CVE-2017-8362.patch
new file mode 100644
index 00000000000..54fbfb44c3b
--- /dev/null
+++ b/media-libs/libsndfile/files/libsndfile-1.0.28-CVE-2017-8362.patch
@@ -0,0 +1,50 @@
+From ef1dbb2df1c0e741486646de40bd638a9c4cd808 Mon Sep 17 00:00:00 2001
+From: Erik de Castro Lopo <er...@mega-nerd.com>
+Date: Fri, 14 Apr 2017 15:19:16 +1000
+Subject: [PATCH] src/flac.c: Fix a buffer read overflow
+
+A file (generated by a fuzzer) which increased the number of channels
+from one frame to the next could cause a read beyond the end of the
+buffer provided by libFLAC. Only option is to abort the read.
+
+Closes: https://github.com/erikd/libsndfile/issues/231
+---
+ src/flac.c | 11 +++++++++--
+ 1 file changed, 9 insertions(+), 2 deletions(-)
+
+diff --git a/src/flac.c b/src/flac.c
+index 5a4f8c21..e4f9aaa0 100644
+--- a/src/flac.c
++++ b/src/flac.c
+@@ -169,6 +169,14 @@ flac_buffer_copy (SF_PRIVATE *psf)
+       const int32_t* const *buffer = pflac->wbuffer ;
+       unsigned i = 0, j, offset, channels, len ;
+ 
++      if (psf->sf.channels != (int) frame->header.channels)
++      {       psf_log_printf (psf, "Error: FLAC frame changed from %d to %d 
channels\n"
++                                                                      
"Nothing to do but to error out.\n" ,
++                                                                      
psf->sf.channels, frame->header.channels) ;
++              psf->error = SFE_FLAC_CHANNEL_COUNT_CHANGED ;
++              return 0 ;
++              } ;
++
+       /*
+       **      frame->header.blocksize is variable and we're using a constant 
blocksize
+       **      of FLAC__MAX_BLOCK_SIZE.
+@@ -202,7 +210,6 @@ flac_buffer_copy (SF_PRIVATE *psf)
+               return 0 ;
+               } ;
+ 
+-
+       len = SF_MIN (pflac->len, frame->header.blocksize) ;
+ 
+       if (pflac->remain % channels != 0)
+@@ -436,7 +443,7 @@ sf_flac_meta_callback (const FLAC__StreamDecoder * UNUSED 
(decoder), const FLAC_
+       {       case FLAC__METADATA_TYPE_STREAMINFO :
+                       if (psf->sf.channels > 0 && psf->sf.channels != (int) 
metadata->data.stream_info.channels)
+                       {       psf_log_printf (psf, "Error: FLAC stream 
changed from %d to %d channels\n"
+-                                                                      
"Nothing to be but to error out.\n" ,
++                                                                      
"Nothing to do but to error out.\n" ,
+                                                                       
psf->sf.channels, metadata->data.stream_info.channels) ;
+                               psf->error = SFE_FLAC_CHANNEL_COUNT_CHANGED ;
+                               return ;

diff --git a/media-libs/libsndfile/files/libsndfile-1.0.28-CVE-2017-8363.patch 
b/media-libs/libsndfile/files/libsndfile-1.0.28-CVE-2017-8363.patch
new file mode 100644
index 00000000000..d0aa400bdd9
--- /dev/null
+++ b/media-libs/libsndfile/files/libsndfile-1.0.28-CVE-2017-8363.patch
@@ -0,0 +1,28 @@
+From cd7da8dbf6ee4310d21d9e44b385d6797160d9e8 Mon Sep 17 00:00:00 2001
+From: Erik de Castro Lopo <er...@mega-nerd.com>
+Date: Wed, 12 Apr 2017 20:19:34 +1000
+Subject: [PATCH] src/flac.c: Fix another memory leak
+
+When the FLAC decoder was passed a malformed file, the associated
+`FLAC__StreamDecoder` object was not getting released.
+
+Closes: https://github.com/erikd/libsndfile/issues/233
+---
+ src/flac.c | 4 +++-
+ 1 file changed, 3 insertions(+), 1 deletion(-)
+
+diff --git a/src/flac.c b/src/flac.c
+index 986a7b8f..5a4f8c21 100644
+--- a/src/flac.c
++++ b/src/flac.c
+@@ -841,7 +841,9 @@ flac_read_header (SF_PRIVATE *psf)
+ 
+       psf_log_printf (psf, "End\n") ;
+ 
+-      if (psf->error == 0)
++      if (psf->error != 0)
++              FLAC__stream_decoder_delete (pflac->fsd) ;
++      else
+       {       FLAC__uint64 position ;
+ 
+               FLAC__stream_decoder_get_decode_position (pflac->fsd, 
&position) ;

diff --git a/media-libs/libsndfile/files/libsndfile-1.0.28-CVE-2017-8365.patch 
b/media-libs/libsndfile/files/libsndfile-1.0.28-CVE-2017-8365.patch
new file mode 100644
index 00000000000..1dc5b57f1d3
--- /dev/null
+++ b/media-libs/libsndfile/files/libsndfile-1.0.28-CVE-2017-8365.patch
@@ -0,0 +1,64 @@
+From fd0484aba8e51d16af1e3a880f9b8b857b385eb3 Mon Sep 17 00:00:00 2001
+From: Erik de Castro Lopo <er...@mega-nerd.com>
+Date: Wed, 12 Apr 2017 19:45:30 +1000
+Subject: [PATCH] FLAC: Fix a buffer read overrun
+
+Buffer read overrun occurs when reading a FLAC file that switches
+from 2 channels to one channel mid-stream. Only option is to
+abort the read.
+
+Closes: https://github.com/erikd/libsndfile/issues/230
+---
+ src/common.h  |  1 +
+ src/flac.c    | 13 +++++++++++++
+ src/sndfile.c |  1 +
+ 3 files changed, 15 insertions(+)
+
+diff --git a/src/common.h b/src/common.h
+index 0bd810c3..e2669b6a 100644
+--- a/src/common.h
++++ b/src/common.h
+@@ -725,6 +725,7 @@ enum
+       SFE_FLAC_INIT_DECODER,
+       SFE_FLAC_LOST_SYNC,
+       SFE_FLAC_BAD_SAMPLE_RATE,
++      SFE_FLAC_CHANNEL_COUNT_CHANGED,
+       SFE_FLAC_UNKOWN_ERROR,
+ 
+       SFE_WVE_NOT_WVE,
+diff --git a/src/flac.c b/src/flac.c
+index 84de0e26..986a7b8f 100644
+--- a/src/flac.c
++++ b/src/flac.c
+@@ -434,6 +434,19 @@ sf_flac_meta_callback (const FLAC__StreamDecoder * UNUSED 
(decoder), const FLAC_
+ 
+       switch (metadata->type)
+       {       case FLAC__METADATA_TYPE_STREAMINFO :
++                      if (psf->sf.channels > 0 && psf->sf.channels != (int) 
metadata->data.stream_info.channels)
++                      {       psf_log_printf (psf, "Error: FLAC stream 
changed from %d to %d channels\n"
++                                                                      
"Nothing to be but to error out.\n" ,
++                                                                      
psf->sf.channels, metadata->data.stream_info.channels) ;
++                              psf->error = SFE_FLAC_CHANNEL_COUNT_CHANGED ;
++                              return ;
++                              } ;
++
++                      if (psf->sf.channels > 0 && psf->sf.samplerate != (int) 
metadata->data.stream_info.sample_rate)
++                      {       psf_log_printf (psf, "Warning: FLAC stream 
changed sample rates from %d to %d.\n"
++                                                                      
"Carrying on as if nothing happened.",
++                                                                      
psf->sf.samplerate, metadata->data.stream_info.sample_rate) ;
++                              } ;
+                       psf->sf.channels = metadata->data.stream_info.channels ;
+                       psf->sf.samplerate = 
metadata->data.stream_info.sample_rate ;
+                       psf->sf.frames = 
metadata->data.stream_info.total_samples ;
+diff --git a/src/sndfile.c b/src/sndfile.c
+index 41875610..e2a87be8 100644
+--- a/src/sndfile.c
++++ b/src/sndfile.c
+@@ -245,6 +245,7 @@ ErrorStruct SndfileErrors [] =
+       {       SFE_FLAC_INIT_DECODER   , "Error : problem with initialization 
of the flac decoder." },
+       {       SFE_FLAC_LOST_SYNC              , "Error : flac decoder lost 
sync." },
+       {       SFE_FLAC_BAD_SAMPLE_RATE, "Error : flac does not support this 
sample rate." },
++      {       SFE_FLAC_CHANNEL_COUNT_CHANGED, "Error : flac channel changed 
mid stream." },
+       {       SFE_FLAC_UNKOWN_ERROR   , "Error : unknown error in flac 
decoder." },
+ 
+       {       SFE_WVE_NOT_WVE                 , "Error : not a WVE file." },

diff --git a/media-libs/libsndfile/files/libsndfile-1.0.28-CVE-2018-13139.patch 
b/media-libs/libsndfile/files/libsndfile-1.0.28-CVE-2018-13139.patch
index 18e6ae76e62..f75843267b0 100644
--- a/media-libs/libsndfile/files/libsndfile-1.0.28-CVE-2018-13139.patch
+++ b/media-libs/libsndfile/files/libsndfile-1.0.28-CVE-2018-13139.patch
@@ -28,4 +28,4 @@ index 53660310..225b4d54 100644
 +
        state.channels = sfinfo.channels ;
        sfinfo.channels = 1 ;
- 
\ No newline at end of file
+ 

diff --git a/media-libs/libsndfile/libsndfile-1.0.28-r4.ebuild 
b/media-libs/libsndfile/libsndfile-1.0.28-r4.ebuild
new file mode 100644
index 00000000000..0473759374d
--- /dev/null
+++ b/media-libs/libsndfile/libsndfile-1.0.28-r4.ebuild
@@ -0,0 +1,70 @@
+# Copyright 1999-2018 Gentoo Authors
+# Distributed under the terms of the GNU General Public License v2
+
+EAPI=7
+
+PYTHON_COMPAT=( python{2_7,3_4,3_5,3_6} pypy{,3} )
+
+inherit python-any-r1 multilib-minimal
+
+MY_P=${P/_pre/pre}
+
+DESCRIPTION="C library for reading and writing files containing sampled sound"
+HOMEPAGE="http://www.mega-nerd.com/libsndfile";
+if [[ ${MY_P} == ${P} ]]; then
+       SRC_URI="http://www.mega-nerd.com/libsndfile/files/${P}.tar.gz";
+else
+       SRC_URI="http://www.mega-nerd.com/tmp/${MY_P}b.tar.gz";
+fi
+
+LICENSE="LGPL-2.1"
+SLOT="0"
+KEYWORDS="~alpha ~amd64 ~arm ~arm64 ~hppa ~ia64 ~mips ~ppc ~ppc64 ~sh ~sparc 
~x86 ~amd64-fbsd ~x86-fbsd ~amd64-linux ~x86-linux ~ppc-macos ~x64-macos 
~x86-macos ~sparc-solaris ~x64-solaris ~x86-solaris"
+IUSE="alsa minimal sqlite static-libs test"
+
+RDEPEND="
+       !minimal? (
+               >=media-libs/flac-1.2.1-r5[${MULTILIB_USEDEP}]
+               >=media-libs/libogg-1.3.0[${MULTILIB_USEDEP}]
+               >=media-libs/libvorbis-1.3.3-r1[${MULTILIB_USEDEP}]
+       )
+       alsa? ( media-libs/alsa-lib )
+       sqlite? ( >=dev-db/sqlite-3.2 )"
+DEPEND="${RDEPEND}"
+BDEPEND="
+       virtual/pkgconfig
+       test? ( ${PYTHON_DEPS} )"
+
+S=${WORKDIR}/${MY_P}
+
+PATCHES=(
+       "${FILESDIR}"/${P}-arm-varargs-failure.patch
+       "${FILESDIR}"/${P}-CVE-2017-12562.patch
+       "${FILESDIR}"/${P}-CVE-2018-13139.patch
+       "${FILESDIR}"/${P}-CVE-2017-6892.patch
+       "${FILESDIR}"/${P}-CVE-2017-836{3,5,2}.patch
+       "${FILESDIR}"/${P}-CVE-2017-14634.patch
+)
+
+pkg_setup() {
+       use test && python-any-r1_pkg_setup
+}
+
+multilib_src_configure() {
+       ECONF_SOURCE="${S}" econf \
+               --disable-octave \
+               --enable-gcc-pipe \
+               --enable-gcc-opt \
+               $(use_enable static-libs static) \
+               $(use_enable !minimal external-libs) \
+               $(multilib_native_enable full-suite) \
+               $(multilib_native_use_enable alsa) \
+               $(multilib_native_use_enable sqlite)
+}
+
+multilib_src_install_all() {
+       einstalldocs
+
+       # package provides .pc files
+       find "${D}" -name '*.la' -delete || die
+}

Reply via email to