From 4db6c490d60e415a37b44d3f28e42271bb0f76be Mon Sep 17 00:00:00 2001 From: jdymitarai Date: Thu, 10 Sep 2026 13:00:38 +0800 Subject: [PATCH] fix(python): check each parameter in native callback validation loop --- python/_jsonnet.c | 2 +- python/_jsonnet_test.py | 12 +++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/python/_jsonnet.c b/python/_jsonnet.c index 00cace766..b9f7b93df 100644 --- a/python/_jsonnet.c +++ b/python/_jsonnet.c @@ -411,7 +411,7 @@ static int handle_native_callbacks(struct JsonnetVm *vm, PyObject *native_callba /* Check the params are all strings */ num_params = PyTuple_Size(params); for (i = 0; i < num_params ; ++i) { - PyObject *param = PyTuple_GetItem(params, 0); + PyObject *param = PyTuple_GetItem(params, i); if (!PyUnicode_Check(param)) { PyErr_SetString(PyExc_TypeError, "native callback param must be string"); goto bad; diff --git a/python/_jsonnet_test.py b/python/_jsonnet_test.py index ddb09c74e..c948c167c 100644 --- a/python/_jsonnet_test.py +++ b/python/_jsonnet_test.py @@ -177,7 +177,17 @@ def test_double_import(self): import_callback=import_callback_encode, native_callbacks=native_callbacks, ) - self.assertEqual(json_str, "84\n") + def test_native_callback_param_type_validation(self): + def dummy_cb(*args): + return None + + # Verify that non-string parameters beyond the first index are rejected with TypeError + with self.assertRaises(TypeError): + _jsonnet.evaluate_snippet( + self.test_filename, + "null", + native_callbacks={"invalid_param": (("valid", 123), dummy_cb)}, + ) if __name__ == '__main__': unittest.main()