Blame SOURCES/libsndfile-1.0.28-flacbufovfl.patch

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