shithub: opus

Download patch

ref: 148ccd812ab67331670854f6f46b85e49007d0de
parent: 360fd07115618a0104e314f4f93575c1b1f46717
author: Jean-Marc Valin <jeanmarcv@google.com>
date: Wed Feb 12 06:19:55 EST 2025

Abort if we overflow the pseudostack

--- a/celt/arch.h
+++ b/celt/arch.h
@@ -56,7 +56,7 @@
 
 #define CELT_SIG_SCALE 32768.f
 
-#define CELT_FATAL(str) celt_fatal(str, __FILE__, __LINE__);
+#define CELT_FATAL(str) celt_fatal(str, __FILE__, __LINE__)
 
 #if defined(ENABLE_ASSERTIONS) || defined(ENABLE_HARDENING)
 #ifdef __GNUC__
--- a/celt/stack_alloc.h
+++ b/celt/stack_alloc.h
@@ -140,8 +140,9 @@
 
 #else
 
+#include "arch.h"
 #define ALIGN(stack, size) ((stack) += ((size) - (long)(stack)) & ((size) - 1))
-#define PUSH(stack, size, type) (ALIGN((stack),sizeof(type)/(sizeof(char))),(stack)+=(size)*(sizeof(type)/(sizeof(char))),(type*)((stack)-(size)*(sizeof(type)/(sizeof(char)))))
+#define PUSH(stack, size, type) (ALIGN((stack),sizeof(type)/(sizeof(char))),(void)(((int)((size)*(sizeof(type)/(sizeof(char)))) <= (scratch_ptr)+GLOBAL_STACK_SIZE-(stack))?0:CELT_FATAL("pseudostack overflow")),(stack)+=(size)*(sizeof(type)/(sizeof(char))),(type*)((stack)-(size)*(sizeof(type)/(sizeof(char)))))
 #if 0 /* Set this to 1 to instrument pseudostack usage */
 #define RESTORE_STACK (printf("%ld %s:%d\n", global_stack-scratch_ptr, __FILE__, __LINE__),global_stack = _saved_stack)
 #else
--