From 969ac73d19d35bacc92b41ceae24246b5d965185 Mon Sep 17 00:00:00 2001 From: dance858 Date: Sat, 23 May 2026 04:07:59 -0700 Subject: [PATCH 1/2] Fix stack-buffer-overflows in numerical-derivative tests --- tests/problem/test_param_broadcast.h | 12 ++++++++---- .../wsum_hess/composite/test_chain_rule_wsum_hess.h | 4 ++-- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/tests/problem/test_param_broadcast.h b/tests/problem/test_param_broadcast.h index 377121a..adbf180 100644 --- a/tests/problem/test_param_broadcast.h +++ b/tests/problem/test_param_broadcast.h @@ -192,8 +192,10 @@ const char *test_const_sum_scalar_mult(void) problem_init_derivatives(prob); - /* point for evaluating */ - double x_vals[1] = {4.0}; + /* point for evaluating. Sized at n_vars (numerical derivative reads + n_vars doubles); only x_vals[0] feeds the lone variable, the rest + are unused but must be in valid memory. */ + double x_vals[6] = {4.0, 0.0, 0.0, 0.0, 0.0, 0.0}; problem_constraint_forward(prob, x_vals); double constrs[1] = {6.0 * 4.0}; @@ -226,8 +228,10 @@ const char *test_param_sum_scalar_mult(void) problem_register_params(prob, param_nodes, 1); problem_init_derivatives(prob); - /* point for evaluating */ - double x_vals[1] = {4.0}; + /* point for evaluating. Sized at n_vars (numerical derivative reads + n_vars doubles); only x_vals[0] feeds the lone variable, the rest + are unused but must be in valid memory. */ + double x_vals[6] = {4.0, 0.0, 0.0, 0.0, 0.0, 0.0}; problem_constraint_forward(prob, x_vals); double constrs[1] = {6.0 * 4.0}; diff --git a/tests/wsum_hess/composite/test_chain_rule_wsum_hess.h b/tests/wsum_hess/composite/test_chain_rule_wsum_hess.h index d8b943b..296dd3c 100644 --- a/tests/wsum_hess/composite/test_chain_rule_wsum_hess.h +++ b/tests/wsum_hess/composite/test_chain_rule_wsum_hess.h @@ -300,13 +300,13 @@ const char *test_wsum_hess_AX_BX_multiply(void) const char *test_wsum_hess_multiply_deep_composite(void) { - double u_vals[4] = {1.0, 2.0, 3.0, 4.0}; + double u_vals[8] = {1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0}; double w[4] = {1.1, 2.2, 3.3, 4.4}; CSR_matrix *A = new_csr_random(2, 2, 1.0); CSR_matrix *B = new_csr_random(2, 2, 1.0); expr *X = new_variable(2, 2, 0, 8); - expr *Y = new_variable(2, 2, 0, 8); + expr *Y = new_variable(2, 2, 4, 8); expr *AX = new_left_matmul(NULL, X, A); expr *BY = new_left_matmul(NULL, Y, B); expr *sin_AX = new_sin(AX); From f1ae7833f66cbed3258632c3b9bbc1d7a3c77b34 Mon Sep 17 00:00:00 2001 From: dance858 Date: Sat, 23 May 2026 04:12:28 -0700 Subject: [PATCH 2/2] remove comment --- tests/problem/test_param_broadcast.h | 6 ------ 1 file changed, 6 deletions(-) diff --git a/tests/problem/test_param_broadcast.h b/tests/problem/test_param_broadcast.h index adbf180..c64d64b 100644 --- a/tests/problem/test_param_broadcast.h +++ b/tests/problem/test_param_broadcast.h @@ -192,9 +192,6 @@ const char *test_const_sum_scalar_mult(void) problem_init_derivatives(prob); - /* point for evaluating. Sized at n_vars (numerical derivative reads - n_vars doubles); only x_vals[0] feeds the lone variable, the rest - are unused but must be in valid memory. */ double x_vals[6] = {4.0, 0.0, 0.0, 0.0, 0.0, 0.0}; problem_constraint_forward(prob, x_vals); @@ -228,9 +225,6 @@ const char *test_param_sum_scalar_mult(void) problem_register_params(prob, param_nodes, 1); problem_init_derivatives(prob); - /* point for evaluating. Sized at n_vars (numerical derivative reads - n_vars doubles); only x_vals[0] feeds the lone variable, the rest - are unused but must be in valid memory. */ double x_vals[6] = {4.0, 0.0, 0.0, 0.0, 0.0, 0.0}; problem_constraint_forward(prob, x_vals);