Revision
17108
Author
anthm
Date
2010-03-25 16:36:11 -0500 (Thu, 25 Mar 2010)

Log Message

add sanity check to project size of decoded codec data

Modified Paths

Diff

Modified: freeswitch/trunk/src/switch_core_codec.c (17107 => 17108)


--- freeswitch/trunk/src/switch_core_codec.c	2010-03-25 21:29:04 UTC (rev 17107)
+++ freeswitch/trunk/src/switch_core_codec.c	2010-03-25 21:36:11 UTC (rev 17108)
@@ -621,6 +621,15 @@
 		return SWITCH_STATUS_NOT_INITALIZED;
 	}
 
+	if (codec->implementation->encoded_bytes_per_packet) {
+		uint32_t frames = encoded_data_len / codec->implementation->encoded_bytes_per_packet;
+
+		if (frames && codec->implementation->decoded_bytes_per_packet * frames > *decoded_data_len) {
+			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Buffer size sanity check failed!\n");
+			return SWITCH_STATUS_GENERR;
+		}
+	}
+	
 	if (codec->mutex)
 		switch_mutex_lock(codec->mutex);
 	status = codec->implementation->decode(codec, other_codec, encoded_data, encoded_data_len, encoded_rate,