shithub: libsamplerate

Download patch

ref: f4e2bc3ff0229f9563261f8294205aac3ba66a8d
parent: a25ac789c019b25870bcf20d35498f95ad610336
author: Erik de Castro Lopo <erikd@mega-nerd.com>
date: Mon Aug 27 15:31:18 EDT 2012

src/src_*.c : Validate internally stashed src_ratio value.

--- a/ChangeLog
+++ b/ChangeLog
@@ -4,6 +4,9 @@
     Add SRC_ERR_BAD_INTERNAL_STATE error number and string.
     Move function is_bad_src_ratio() to common.h.
 
+    * src/src_linear.c src/src_sinc.c src/src_zoh.c
+    Validate internally stashed src_ratio value.
+
 2012-08-23  Erik de Castro Lopo  <erikd AT mega-nerd DOT com>
 
     * tests/multi_channel_test.c tests/snr_bw_test.c tests/varispeed_test.c
--- a/src/src_linear.c
+++ b/src/src_linear.c
@@ -1,5 +1,5 @@
 /*
-** Copyright (C) 2002-2011 Erik de Castro Lopo <erikd@mega-nerd.com>
+** Copyright (C) 2002-2012 Erik de Castro Lopo <erikd@mega-nerd.com>
 **
 ** 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
@@ -78,6 +78,10 @@
 	priv->in_used = priv->out_gen = 0 ;
 
 	src_ratio = psrc->last_ratio ;
+
+	if (is_bad_src_ratio (src_ratio))
+		return SRC_ERR_BAD_INTERNAL_STATE ;
+
 	input_index = psrc->last_position ;
 
 	/* Calculate samples before first sample in input array. */
--- a/src/src_sinc.c
+++ b/src/src_sinc.c
@@ -347,6 +347,9 @@
 
 	src_ratio = psrc->last_ratio ;
 
+	if (is_bad_src_ratio (src_ratio))
+		return SRC_ERR_BAD_INTERNAL_STATE ;
+
 	/* Check the sample rate ratio wrt the buffer len. */
 	count = (filter->coeff_half_len + 2.0) / filter->index_inc ;
 	if (MIN (psrc->last_ratio, data->src_ratio) < 1.0)
@@ -493,6 +496,9 @@
 
 	src_ratio = psrc->last_ratio ;
 
+	if (is_bad_src_ratio (src_ratio))
+		return SRC_ERR_BAD_INTERNAL_STATE ;
+
 	/* Check the sample rate ratio wrt the buffer len. */
 	count = (filter->coeff_half_len + 2.0) / filter->index_inc ;
 	if (MIN (psrc->last_ratio, data->src_ratio) < 1.0)
@@ -644,6 +650,9 @@
 
 	src_ratio = psrc->last_ratio ;
 
+	if (is_bad_src_ratio (src_ratio))
+		return SRC_ERR_BAD_INTERNAL_STATE ;
+
 	/* Check the sample rate ratio wrt the buffer len. */
 	count = (filter->coeff_half_len + 2.0) / filter->index_inc ;
 	if (MIN (psrc->last_ratio, data->src_ratio) < 1.0)
@@ -801,6 +810,9 @@
 
 	src_ratio = psrc->last_ratio ;
 
+	if (is_bad_src_ratio (src_ratio))
+		return SRC_ERR_BAD_INTERNAL_STATE ;
+
 	/* Check the sample rate ratio wrt the buffer len. */
 	count = (filter->coeff_half_len + 2.0) / filter->index_inc ;
 	if (MIN (psrc->last_ratio, data->src_ratio) < 1.0)
@@ -1044,6 +1056,9 @@
 	filter->in_used = filter->out_gen = 0 ;
 
 	src_ratio = psrc->last_ratio ;
+
+	if (is_bad_src_ratio (src_ratio))
+		return SRC_ERR_BAD_INTERNAL_STATE ;
 
 	/* Check the sample rate ratio wrt the buffer len. */
 	count = (filter->coeff_half_len + 2.0) / filter->index_inc ;
--- a/src/src_zoh.c
+++ b/src/src_zoh.c
@@ -1,5 +1,5 @@
 /*
-** Copyright (C) 2002-2011 Erik de Castro Lopo <erikd@mega-nerd.com>
+** Copyright (C) 2002-2012 Erik de Castro Lopo <erikd@mega-nerd.com>
 **
 ** 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
@@ -76,6 +76,10 @@
 	priv->in_used = priv->out_gen = 0 ;
 
 	src_ratio = psrc->last_ratio ;
+
+	if (is_bad_src_ratio (src_ratio))
+		return SRC_ERR_BAD_INTERNAL_STATE ;
+
 	input_index = psrc->last_position ;
 
 	/* Calculate samples before first sample in input array. */