From 6a2f323ac2c53b32d8a1d47b36dd0d0786027a7c Mon Sep 17 00:00:00 2001 From: Nghia Truong <7416935+ttnghia@users.noreply.github.com> Date: Wed, 21 Aug 2024 07:35:44 -0700 Subject: [PATCH] Fix function parameters with common dependency modified during their evaluation (#16620) This fixes an issue in JNI C++ code. In particular, during a function call, the two passing parameters are evaluated using an index value, but that index is modified during evaluating one of the parameters, leading to out-of-bound access when evaluating the other. Authors: - Nghia Truong (https://github.com/ttnghia) Approvers: - Jason Lowe (https://github.com/jlowe) URL: https://github.com/rapidsai/cudf/pull/16620 --- java/src/main/native/src/TableJni.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/java/src/main/native/src/TableJni.cpp b/java/src/main/native/src/TableJni.cpp index 76ca8c533ce..ecc551f1143 100644 --- a/java/src/main/native/src/TableJni.cpp +++ b/java/src/main/native/src/TableJni.cpp @@ -1037,9 +1037,9 @@ cudf::io::schema_element read_schema_element(int& index, // go to the next entry, so recursion can parse it. index++; for (int i = 0; i < num_children; i++) { + auto const name = std::string{names.get(index).get()}; child_elems.insert( - std::pair{names.get(index).get(), - cudf::jni::read_schema_element(index, children, names, types, scales)}); + std::pair{name, cudf::jni::read_schema_element(index, children, names, types, scales)}); } return cudf::io::schema_element{d_type, std::move(child_elems)}; } else { @@ -1830,9 +1830,9 @@ Java_ai_rapids_cudf_Table_readJSONFromDataSource(JNIEnv* env, std::map data_types; int at = 0; while (at < n_types.size()) { + auto const name = std::string{n_col_names.get(at).get()}; data_types.insert(std::pair{ - n_col_names.get(at).get(), - cudf::jni::read_schema_element(at, n_children, n_col_names, n_types, n_scales)}); + name, cudf::jni::read_schema_element(at, n_children, n_col_names, n_types, n_scales)}); } opts.dtypes(data_types); } else { @@ -1929,9 +1929,9 @@ JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Table_readJSON(JNIEnv* env, std::map data_types; int at = 0; while (at < n_types.size()) { + auto const name = std::string{n_col_names.get(at).get()}; data_types.insert(std::pair{ - n_col_names.get(at).get(), - cudf::jni::read_schema_element(at, n_children, n_col_names, n_types, n_scales)}); + name, cudf::jni::read_schema_element(at, n_children, n_col_names, n_types, n_scales)}); } opts.dtypes(data_types); } else {