Blame SOURCES/libsndfile-1.0.28-flacbufovfl.patch

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