Index: b/funcs/func_speex.c
===================================================================
--- a/funcs/func_speex.c
+++ b/funcs/func_speex.c
@@ -169,6 +169,23 @@ static int speex_callback(struct ast_aud
 
 	if ((sdi->samples != frame->samples) || (ast_format_get_sample_rate(frame->subclass.format) != si->lastrate)) {
 		si->lastrate = ast_format_get_sample_rate(frame->subclass.format);
+
+		/*
+			protect against invalid datastore info
+			in some cases ast_channel_datastore_find returns a corrupted datastore
+			so avoid crashing when calling speex_preprocess_state_init
+			it will maybe crash somewhere else later as the si structure is corrupted 
+		*/
+		if (si->lastrate < 4000) {
+			ast_log(LOG_ERROR, "Invalid rate\n");
+			return -1;
+		}
+
+		if (!frame->samples) {
+			ast_log(LOG_ERROR, "No sample to process\n");
+			return -1;
+		}
+
 		if (sdi->state) {
 			speex_preprocess_state_destroy(sdi->state);
 		}
