pitrou commented on code in PR #51758:
URL: https://github.com/apache/arrow/pull/51758#discussion_r4196695500


##########
cpp/src/arrow/util/simdjson_internal.cc:
##########
@@ -538,47 +538,57 @@ Result<std::string> MinifyJson(std::string_view json) {
   return minified;
 }
 
-Status ConsumeJsonValue(simdjson::ondemand::value value) {
-  return VisitJsonValue(
-      value, ValidateJsonObject, ValidateJsonArray,
-      [](std::string_view) { return Status::OK(); }, [](bool) { return 
Status::OK(); },
-      []() { return Status::OK(); }, [](int64_t) { return Status::OK(); },
-      [](uint64_t) { return Status::OK(); }, [](double) { return Status::OK(); 
},
-      [](simdjson::ondemand::value) { return Status::OK(); });
-}
-
-Status ValidateJsonObject(simdjson::ondemand::object object) {
+static Status ValidateJsonObject(simdjson::ondemand::object object, int 
max_depth,
+                                 int depth) {
+  if (ARROW_PREDICT_FALSE(depth >= max_depth)) {
+    return Status::Invalid("JSON too deeply nested: max nesting depth is ", 
max_depth);
+  }
   for (auto field_result : object) {
     ARROW_ASSIGN_OR_RAISE(
         auto field, ResolveSimdjsonResult(field_result, "Failed to iterate 
JSON object"));
-
-    RETURN_NOT_OK(ConsumeJsonValue(field.value()));
+    RETURN_NOT_OK(ConsumeJsonValue(field.value(), max_depth, depth));
   }
-
   return Status::OK();
 }
 
-Status ValidateJsonArray(simdjson::ondemand::array array) {
+static Status ValidateJsonArray(simdjson::ondemand::array array, int max_depth,
+                                int depth) {
+  if (ARROW_PREDICT_FALSE(depth >= max_depth)) {
+    return Status::Invalid("JSON too deeply nested: max nesting depth is ", 
max_depth);
+  }
   for (auto element_result : array) {
     ARROW_ASSIGN_OR_RAISE(
         auto value,
         ResolveSimdjsonResult(element_result, "Failed to iterate JSON array"));
-
-    RETURN_NOT_OK(ConsumeJsonValue(value));
+    RETURN_NOT_OK(ConsumeJsonValue(value, max_depth, depth));
   }
-
   return Status::OK();
 }
 
+Status ConsumeJsonValue(simdjson::ondemand::value value, int max_depth, int 
depth) {

Review Comment:
   Good point, will do.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to