This is an automated email from the ASF dual-hosted git repository.

chaokunyang pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/fory.git


The following commit(s) were added to refs/heads/main by this push:
     new e2756a7de feat(c++): check max dyn depth when deserializing 
polymorphic types (#2939)
e2756a7de is described below

commit e2756a7ded064c4de59a494abc728b28ded40ddd
Author: Shawn Yang <[email protected]>
AuthorDate: Thu Nov 27 19:30:18 2025 +0800

    feat(c++): check max dyn depth when deserializing polymorphic types (#2939)
    
    ## Why?
    <!-- Describe the purpose of this PR. -->
    
    ## What does this PR do?
    
    check max dyn depth when deserializing polymorphic types
    
    ## Related issues
    
    #2906
    
    ## Does this PR introduce any user-facing change?
    
    <!--
    If any user-facing interface changes, please [open an
    issue](https://github.com/apache/fory/issues/new/choose) describing the
    need to do so and update the document if necessary.
    
    Delete section if not applicable.
    -->
    
    - [ ] Does this PR introduce any public API change?
    - [ ] Does this PR introduce any binary protocol compatibility change?
    
    ## Benchmark
    
    <!--
    When the PR has an impact on performance (if you don't know whether the
    PR will have an impact on performance, you can submit the PR first, and
    if it will have impact on performance, the code reviewer will explain
    it), be sure to attach a benchmark data here.
    
    Delete section if not applicable.
    -->
---
 cpp/fory/serialization/config.h                    |   8 +-
 cpp/fory/serialization/context.cc                  |   8 +-
 cpp/fory/serialization/context.h                   |  89 ++++++++--------
 cpp/fory/serialization/fory.h                      |  14 ++-
 cpp/fory/serialization/serialization_test.cc       |   4 +-
 cpp/fory/serialization/skip.cc                     |   8 +-
 .../serialization/smart_ptr_serializer_test.cc     | 115 +++++++++++++++++++++
 cpp/fory/serialization/smart_ptr_serializers.h     |  18 ++++
 cpp/fory/serialization/struct_serializer.h         |   6 --
 cpp/fory/serialization/struct_test.cc              |  39 -------
 10 files changed, 202 insertions(+), 107 deletions(-)

diff --git a/cpp/fory/serialization/config.h b/cpp/fory/serialization/config.h
index 6dfd1f31c..d471c3907 100644
--- a/cpp/fory/serialization/config.h
+++ b/cpp/fory/serialization/config.h
@@ -42,9 +42,11 @@ struct Config {
   /// When enabled, validates type hashes to detect schema mismatches.
   bool check_struct_version = false;
 
-  /// Maximum allowed nesting depth for preventing stack overflow.
-  /// Default is 64 levels deep.
-  uint32_t max_depth = 64;
+  /// Maximum allowed nesting depth for dynamically-typed objects (polymorphic
+  /// types like shared_ptr<Base>, unique_ptr<Base>). This prevents stack
+  /// overflow from deeply nested structures in dynamic serialization 
scenarios.
+  /// Default is 5 levels deep.
+  uint32_t max_dyn_depth = 5;
 
   /// Enable reference tracking for shared and circular references.
   /// When enabled, avoids duplicating shared objects and handles cycles.
diff --git a/cpp/fory/serialization/context.cc 
b/cpp/fory/serialization/context.cc
index a29609697..782f282c4 100644
--- a/cpp/fory/serialization/context.cc
+++ b/cpp/fory/serialization/context.cc
@@ -97,7 +97,7 @@ encode_meta_string(const std::string &value, bool 
is_namespace) {
 WriteContext::WriteContext(const Config &config,
                            std::shared_ptr<TypeResolver> type_resolver)
     : buffer_(), config_(&config), type_resolver_(std::move(type_resolver)),
-      current_depth_(0) {}
+      current_dyn_depth_(0) {}
 
 WriteContext::~WriteContext() = default;
 
@@ -247,7 +247,7 @@ void WriteContext::reset() {
   ref_writer_.reset();
   write_type_defs_.clear();
   write_type_id_index_map_.clear();
-  current_depth_ = 0;
+  current_dyn_depth_ = 0;
   // Reset buffer for reuse
   buffer_.WriterIndex(0);
   buffer_.ReaderIndex(0);
@@ -260,7 +260,7 @@ void WriteContext::reset() {
 ReadContext::ReadContext(const Config &config,
                          std::shared_ptr<TypeResolver> type_resolver)
     : buffer_(nullptr), config_(&config),
-      type_resolver_(std::move(type_resolver)), current_depth_(0) {}
+      type_resolver_(std::move(type_resolver)), current_dyn_depth_(0) {}
 
 ReadContext::~ReadContext() = default;
 
@@ -417,7 +417,7 @@ void ReadContext::reset() {
   ref_reader_.reset();
   reading_type_infos_.clear();
   parsed_type_infos_.clear();
-  current_depth_ = 0;
+  current_dyn_depth_ = 0;
   meta_string_table_.reset();
 }
 
diff --git a/cpp/fory/serialization/context.h b/cpp/fory/serialization/context.h
index 77ca3afde..c9545cc2e 100644
--- a/cpp/fory/serialization/context.h
+++ b/cpp/fory/serialization/context.h
@@ -37,18 +37,19 @@ namespace serialization {
 class TypeResolver;
 class ReadContext;
 
-/// RAII helper to automatically decrease depth when leaving scope
-class DepthGuard {
+/// RAII helper to automatically decrease dynamic depth when leaving scope.
+/// Used for tracking nested polymorphic type deserialization depth.
+class DynDepthGuard {
 public:
-  explicit DepthGuard(ReadContext &ctx) : ctx_(ctx) {}
+  explicit DynDepthGuard(ReadContext &ctx) : ctx_(ctx) {}
 
-  ~DepthGuard();
+  ~DynDepthGuard();
 
   // Non-copyable, non-movable
-  DepthGuard(const DepthGuard &) = delete;
-  DepthGuard &operator=(const DepthGuard &) = delete;
-  DepthGuard(DepthGuard &&) = delete;
-  DepthGuard &operator=(DepthGuard &&) = delete;
+  DynDepthGuard(const DynDepthGuard &) = delete;
+  DynDepthGuard &operator=(const DynDepthGuard &) = delete;
+  DynDepthGuard(DynDepthGuard &&) = delete;
+  DynDepthGuard &operator=(DynDepthGuard &&) = delete;
 
 private:
   ReadContext &ctx_;
@@ -109,29 +110,29 @@ public:
   /// Check if reference tracking is enabled.
   inline bool track_ref() const { return config_->track_ref; }
 
-  /// Get maximum allowed nesting depth.
-  inline uint32_t max_depth() const { return config_->max_depth; }
+  /// Get maximum allowed dynamic nesting depth for polymorphic types.
+  inline uint32_t max_dyn_depth() const { return config_->max_dyn_depth; }
 
-  /// Get current nesting depth.
-  inline uint32_t current_depth() const { return current_depth_; }
+  /// Get current dynamic nesting depth.
+  inline uint32_t current_dyn_depth() const { return current_dyn_depth_; }
 
-  /// Increase nesting depth by 1.
+  /// Increase dynamic nesting depth by 1.
   ///
-  /// @return Error if max depth exceeded, success otherwise.
-  inline Result<void, Error> increase_depth() {
-    if (current_depth_ >= config_->max_depth) {
-      return Unexpected(
-          Error::depth_exceed("Max serialization depth exceeded: " +
-                              std::to_string(config_->max_depth)));
+  /// @return Error if max dynamic depth exceeded, success otherwise.
+  inline Result<void, Error> increase_dyn_depth() {
+    if (current_dyn_depth_ >= config_->max_dyn_depth) {
+      return Unexpected<Error>(
+          Error::depth_exceed("Max dynamic serialization depth exceeded: " +
+                              std::to_string(config_->max_dyn_depth)));
     }
-    current_depth_++;
+    current_dyn_depth_++;
     return Result<void, Error>();
   }
 
-  /// Decrease nesting depth by 1.
-  inline void decrease_depth() {
-    if (current_depth_ > 0) {
-      current_depth_--;
+  /// Decrease dynamic nesting depth by 1.
+  inline void decrease_dyn_depth() {
+    if (current_dyn_depth_ > 0) {
+      current_dyn_depth_--;
     }
   }
 
@@ -210,7 +211,7 @@ private:
   const Config *config_;
   std::shared_ptr<TypeResolver> type_resolver_;
   RefWriter ref_writer_;
-  uint32_t current_depth_;
+  uint32_t current_dyn_depth_;
 
   // Meta sharing state (for compatible mode)
   std::vector<std::vector<uint8_t>> write_type_defs_;
@@ -285,29 +286,29 @@ public:
   /// Check if reference tracking is enabled.
   inline bool track_ref() const { return config_->track_ref; }
 
-  /// Get maximum allowed nesting depth.
-  inline uint32_t max_depth() const { return config_->max_depth; }
+  /// Get maximum allowed dynamic nesting depth for polymorphic types.
+  inline uint32_t max_dyn_depth() const { return config_->max_dyn_depth; }
 
-  /// Get current nesting depth.
-  inline uint32_t current_depth() const { return current_depth_; }
+  /// Get current dynamic nesting depth.
+  inline uint32_t current_dyn_depth() const { return current_dyn_depth_; }
 
-  /// Increase nesting depth by 1.
+  /// Increase dynamic nesting depth by 1.
   ///
-  /// @return Error if max depth exceeded, success otherwise.
-  inline Result<void, Error> increase_depth() {
-    if (current_depth_ >= config_->max_depth) {
-      return Unexpected(
-          Error::depth_exceed("Max deserialization depth exceeded: " +
-                              std::to_string(config_->max_depth)));
+  /// @return Error if max dynamic depth exceeded, success otherwise.
+  inline Result<void, Error> increase_dyn_depth() {
+    if (current_dyn_depth_ >= config_->max_dyn_depth) {
+      return Unexpected<Error>(
+          Error::depth_exceed("Max dynamic deserialization depth exceeded: " +
+                              std::to_string(config_->max_dyn_depth)));
     }
-    current_depth_++;
+    current_dyn_depth_++;
     return Result<void, Error>();
   }
 
-  /// Decrease nesting depth by 1.
-  inline void decrease_depth() {
-    if (current_depth_ > 0) {
-      current_depth_--;
+  /// Decrease dynamic nesting depth by 1.
+  inline void decrease_dyn_depth() {
+    if (current_dyn_depth_ > 0) {
+      current_dyn_depth_--;
     }
   }
 
@@ -380,7 +381,7 @@ private:
   const Config *config_;
   std::shared_ptr<TypeResolver> type_resolver_;
   RefReader ref_reader_;
-  uint32_t current_depth_;
+  uint32_t current_dyn_depth_;
 
   // Meta sharing state (for compatible mode)
   std::vector<std::shared_ptr<TypeInfo>> reading_type_infos_;
@@ -390,8 +391,8 @@ private:
   meta::MetaStringTable meta_string_table_;
 };
 
-/// Implementation of DepthGuard destructor
-inline DepthGuard::~DepthGuard() { ctx_.decrease_depth(); }
+/// Implementation of DynDepthGuard destructor
+inline DynDepthGuard::~DynDepthGuard() { ctx_.decrease_dyn_depth(); }
 
 } // namespace serialization
 } // namespace fory
diff --git a/cpp/fory/serialization/fory.h b/cpp/fory/serialization/fory.h
index 485a3d0fb..3689f08c4 100644
--- a/cpp/fory/serialization/fory.h
+++ b/cpp/fory/serialization/fory.h
@@ -57,7 +57,7 @@ class Fory;
 ///     .compatible(true)
 ///     .xlang(true)
 ///     .check_struct_version(false)
-///     .max_depth(128)
+///     .max_dyn_depth(10)
 ///     .build();
 /// ```
 class ForyBuilder {
@@ -83,9 +83,15 @@ public:
     return *this;
   }
 
-  /// Set maximum allowed nesting depth.
-  ForyBuilder &max_depth(uint32_t depth) {
-    config_.max_depth = depth;
+  /// Set maximum allowed nesting depth for dynamically-typed objects.
+  ///
+  /// This limits the maximum depth for nested polymorphic object serialization
+  /// (e.g., shared_ptr<Base>, unique_ptr<Base>). This prevents stack overflow
+  /// from deeply nested structures in dynamic serialization scenarios.
+  ///
+  /// Default value is 5.
+  ForyBuilder &max_dyn_depth(uint32_t depth) {
+    config_.max_dyn_depth = depth;
     return *this;
   }
 
diff --git a/cpp/fory/serialization/serialization_test.cc 
b/cpp/fory/serialization/serialization_test.cc
index 234e9e5be..a0c1a746d 100644
--- a/cpp/fory/serialization/serialization_test.cc
+++ b/cpp/fory/serialization/serialization_test.cc
@@ -381,14 +381,14 @@ TEST(SerializationTest, ConfigurationBuilder) {
                    .compatible(true)
                    .xlang(false)
                    .check_struct_version(true)
-                   .max_depth(128)
+                   .max_dyn_depth(10)
                    .track_ref(false)
                    .build();
 
   EXPECT_TRUE(fory1.config().compatible);
   EXPECT_FALSE(fory1.config().xlang);
   EXPECT_TRUE(fory1.config().check_struct_version);
-  EXPECT_EQ(fory1.config().max_depth, 128);
+  EXPECT_EQ(fory1.config().max_dyn_depth, 10);
   EXPECT_FALSE(fory1.config().track_ref);
 }
 
diff --git a/cpp/fory/serialization/skip.cc b/cpp/fory/serialization/skip.cc
index c34420526..92626cd6b 100644
--- a/cpp/fory/serialization/skip.cc
+++ b/cpp/fory/serialization/skip.cc
@@ -201,9 +201,6 @@ Result<void, Error> skip_struct(ReadContext &ctx, const 
FieldType &field_type) {
 
   const auto &field_infos = type_info->type_meta->get_field_infos();
 
-  FORY_RETURN_NOT_OK(ctx.increase_depth());
-  DepthGuard guard(ctx);
-
   for (const auto &fi : field_infos) {
     bool read_ref = field_need_write_ref_into_runtime(fi.field_type);
     FORY_RETURN_NOT_OK(skip_field_value(ctx, fi.field_type, read_ref));
@@ -253,8 +250,9 @@ Result<void, Error> skip_ext(ReadContext &ctx, const 
FieldType &field_type) {
                           std::to_string(full_type_id)));
   }
 
-  FORY_RETURN_NOT_OK(ctx.increase_depth());
-  DepthGuard guard(ctx);
+  // Check and increase dynamic depth for polymorphic deserialization
+  FORY_RETURN_NOT_OK(ctx.increase_dyn_depth());
+  DynDepthGuard dyn_depth_guard(ctx);
 
   // Call the harness read_data_fn to skip the data
   // The result is a pointer we need to delete
diff --git a/cpp/fory/serialization/smart_ptr_serializer_test.cc 
b/cpp/fory/serialization/smart_ptr_serializer_test.cc
index 4f3e22550..7cea160da 100644
--- a/cpp/fory/serialization/smart_ptr_serializer_test.cc
+++ b/cpp/fory/serialization/smart_ptr_serializer_test.cc
@@ -325,6 +325,121 @@ TEST(SmartPtrSerializerTest, 
PolymorphicUniquePtrDerived2) {
             5678);
 }
 
+// ============================================================================
+// Max Dynamic Depth Tests
+// ============================================================================
+
+// Container struct for testing nested polymorphic depth limits
+struct NestedContainer {
+  virtual ~NestedContainer() = default;
+  int32_t value = 0;
+  std::shared_ptr<NestedContainer> nested;
+};
+FORY_STRUCT(NestedContainer, value, nested);
+
+inline bool operator==(const NestedContainer &a, const NestedContainer &b) {
+  if (a.value != b.value)
+    return false;
+  if (static_cast<bool>(a.nested) != static_cast<bool>(b.nested))
+    return false;
+  if (a.nested && b.nested)
+    return *a.nested == *b.nested;
+  return true;
+}
+
+// Holder struct to wrap nested container in a polymorphic shared_ptr
+struct NestedContainerHolder {
+  std::shared_ptr<NestedContainer> ptr;
+};
+FORY_STRUCT(NestedContainerHolder, ptr);
+
+TEST(SmartPtrSerializerTest, MaxDynDepthExceeded) {
+  // Create Fory with max_dyn_depth=2
+  auto fory = Fory::builder().xlang(true).max_dyn_depth(2).build();
+  fory.register_struct<NestedContainerHolder>(300);
+  fory.register_struct<NestedContainer>("test", "NestedContainer");
+
+  // Create 3 levels of nesting (exceeds max_dyn_depth=2)
+  auto level3 = std::make_shared<NestedContainer>();
+  level3->value = 3;
+  level3->nested = nullptr;
+
+  auto level2 = std::make_shared<NestedContainer>();
+  level2->value = 2;
+  level2->nested = level3;
+
+  auto level1 = std::make_shared<NestedContainer>();
+  level1->value = 1;
+  level1->nested = level2;
+
+  NestedContainerHolder holder;
+  holder.ptr = level1;
+
+  // Serialize should succeed
+  auto bytes_result = fory.serialize(holder);
+  ASSERT_TRUE(bytes_result.ok()) << bytes_result.error().to_string();
+
+  // Deserialize should fail due to max depth exceeded
+  auto deserialize_result = fory.deserialize<NestedContainerHolder>(
+      bytes_result->data(), bytes_result->size());
+  ASSERT_FALSE(deserialize_result.ok())
+      << "Expected deserialization to fail due to max depth";
+
+  // Check error message mentions depth
+  std::string error_msg = deserialize_result.error().to_string();
+  EXPECT_TRUE(error_msg.find("depth") != std::string::npos ||
+              error_msg.find("Depth") != std::string::npos)
+      << "Error should mention depth: " << error_msg;
+}
+
+TEST(SmartPtrSerializerTest, MaxDynDepthSufficient) {
+  // Create Fory with max_dyn_depth=5 (sufficient for 3 levels)
+  auto fory = Fory::builder().xlang(true).max_dyn_depth(5).build();
+  fory.register_struct<NestedContainerHolder>(300);
+  fory.register_struct<NestedContainer>("test", "NestedContainer");
+
+  // Create 3 levels of nesting
+  auto level3 = std::make_shared<NestedContainer>();
+  level3->value = 3;
+  level3->nested = nullptr;
+
+  auto level2 = std::make_shared<NestedContainer>();
+  level2->value = 2;
+  level2->nested = level3;
+
+  auto level1 = std::make_shared<NestedContainer>();
+  level1->value = 1;
+  level1->nested = level2;
+
+  NestedContainerHolder holder;
+  holder.ptr = level1;
+
+  // Serialize should succeed
+  auto bytes_result = fory.serialize(holder);
+  ASSERT_TRUE(bytes_result.ok()) << bytes_result.error().to_string();
+
+  // Deserialize should succeed with sufficient depth
+  auto deserialize_result = fory.deserialize<NestedContainerHolder>(
+      bytes_result->data(), bytes_result->size());
+  ASSERT_TRUE(deserialize_result.ok())
+      << "Deserialization failed: " << deserialize_result.error().to_string();
+
+  auto deserialized = std::move(deserialize_result).value();
+  ASSERT_TRUE(deserialized.ptr);
+  EXPECT_EQ(deserialized.ptr->value, 1);
+  ASSERT_TRUE(deserialized.ptr->nested);
+  EXPECT_EQ(deserialized.ptr->nested->value, 2);
+  ASSERT_TRUE(deserialized.ptr->nested->nested);
+  EXPECT_EQ(deserialized.ptr->nested->nested->value, 3);
+  EXPECT_FALSE(deserialized.ptr->nested->nested->nested);
+}
+
+TEST(SmartPtrSerializerTest, MaxDynDepthDefault) {
+  // Default max_dyn_depth is 5
+  auto fory = Fory::builder().xlang(true).build();
+  EXPECT_EQ(fory.config().max_dyn_depth, 5);
+}
+
 } // namespace
 } // namespace serialization
 } // namespace fory
\ No newline at end of file
diff --git a/cpp/fory/serialization/smart_ptr_serializers.h 
b/cpp/fory/serialization/smart_ptr_serializers.h
index 33853d4e7..f86e4e3da 100644
--- a/cpp/fory/serialization/smart_ptr_serializers.h
+++ b/cpp/fory/serialization/smart_ptr_serializers.h
@@ -375,6 +375,11 @@ template <typename T> struct 
Serializer<std::shared_ptr<T>> {
             "Cannot deserialize polymorphic std::shared_ptr<T> "
             "without type info (read_type=false)"));
       }
+
+      // Check and increase dynamic depth for polymorphic deserialization
+      FORY_RETURN_NOT_OK(ctx.increase_dyn_depth());
+      DynDepthGuard dyn_depth_guard(ctx);
+
       // Read type info from stream to get the concrete type
       FORY_TRY(type_info, ctx.read_any_typeinfo());
 
@@ -458,6 +463,10 @@ template <typename T> struct 
Serializer<std::shared_ptr<T>> {
 
     // For polymorphic types, use the harness to deserialize the concrete type
     if constexpr (is_polymorphic) {
+      // Check and increase dynamic depth for polymorphic deserialization
+      FORY_RETURN_NOT_OK(ctx.increase_dyn_depth());
+      DynDepthGuard dyn_depth_guard(ctx);
+
       // The type_info contains information about the CONCRETE type, not T
       // Use the harness to deserialize it
       if (!type_info.harness.read_data_fn) {
@@ -647,6 +656,11 @@ template <typename T> struct 
Serializer<std::unique_ptr<T>> {
             "Cannot deserialize polymorphic std::unique_ptr<T> "
             "without type info (read_type=false)"));
       }
+
+      // Check and increase dynamic depth for polymorphic deserialization
+      FORY_RETURN_NOT_OK(ctx.increase_dyn_depth());
+      DynDepthGuard dyn_depth_guard(ctx);
+
       // Read type info from stream to get the concrete type
       FORY_TRY(type_info, ctx.read_any_typeinfo());
 
@@ -703,6 +717,10 @@ template <typename T> struct 
Serializer<std::unique_ptr<T>> {
 
     // For polymorphic types, use the harness to deserialize the concrete type
     if constexpr (is_polymorphic) {
+      // Check and increase dynamic depth for polymorphic deserialization
+      FORY_RETURN_NOT_OK(ctx.increase_dyn_depth());
+      DynDepthGuard dyn_depth_guard(ctx);
+
       if (!type_info.harness.read_data_fn) {
         return Unexpected(Error::type_error(
             "No harness read function for polymorphic type deserialization"));
diff --git a/cpp/fory/serialization/struct_serializer.h 
b/cpp/fory/serialization/struct_serializer.h
index 51bb409d0..cb56b47c9 100644
--- a/cpp/fory/serialization/struct_serializer.h
+++ b/cpp/fory/serialization/struct_serializer.h
@@ -921,9 +921,6 @@ struct Serializer<T, 
std::enable_if_t<is_fory_serializable_v<T>>> {
   static Result<T, Error>
   read_compatible(ReadContext &ctx,
                   std::shared_ptr<TypeInfo> remote_type_info) {
-    FORY_RETURN_NOT_OK(ctx.increase_depth());
-    DepthGuard depth_guard(ctx);
-
     // Read and verify struct version if enabled (matches write_data behavior)
     if (ctx.check_struct_version()) {
       FORY_TRY(read_version, ctx.buffer().ReadInt32());
@@ -958,9 +955,6 @@ struct Serializer<T, 
std::enable_if_t<is_fory_serializable_v<T>>> {
   }
 
   static Result<T, Error> read_data(ReadContext &ctx) {
-    FORY_RETURN_NOT_OK(ctx.increase_depth());
-    DepthGuard depth_guard(ctx);
-
     if (ctx.check_struct_version()) {
       FORY_TRY(read_version, ctx.buffer().ReadInt32());
       FORY_TRY(local_type_info,
diff --git a/cpp/fory/serialization/struct_test.cc 
b/cpp/fory/serialization/struct_test.cc
index 03bd702ed..2a5882d26 100644
--- a/cpp/fory/serialization/struct_test.cc
+++ b/cpp/fory/serialization/struct_test.cc
@@ -505,45 +505,6 @@ TEST(StructComprehensiveTest, OrderMultiple) {
                        Status::COMPLETED});
 }
 
-// Note: Depth limit tests disabled for now as depth tracking semantics
-// need clarification. The core struct serialization works correctly.
-TEST(StructComprehensiveTest, DISABLED_DepthLimitViolation) {
-  auto fory = Fory::builder().xlang(true).max_depth(1).build();
-  // Register types needed for BoundingBox
-  uint32_t type_id = 1;
-  fory.register_struct<Point2D>(type_id++);
-  fory.register_struct<Rectangle>(type_id++);
-  fory.register_struct<BoundingBox>(type_id++);
-
-  BoundingBox bb{{{0, 0}, {10, 10}}, "test"};
-  auto result = fory.serialize(bb);
-  EXPECT_FALSE(result.ok());
-  if (!result.ok()) {
-    std::string error_msg = result.error().to_string();
-    EXPECT_TRUE(error_msg.find("depth") != std::string::npos ||
-                error_msg.find("Depth") != std::string::npos)
-        << "Error should mention depth: " << error_msg;
-  }
-}
-
-TEST(StructComprehensiveTest, DISABLED_SufficientDepthLimit) {
-  auto fory = Fory::builder().xlang(true).max_depth(10).build();
-  // Register types needed for BoundingBox
-  uint32_t type_id = 1;
-  fory.register_struct<Point2D>(type_id++);
-  fory.register_struct<Rectangle>(type_id++);
-  fory.register_struct<BoundingBox>(type_id++);
-
-  BoundingBox bb{{{0, 0}, {10, 10}}, "test"};
-  auto result = fory.serialize(bb);
-  ASSERT_TRUE(result.ok());
-
-  std::vector<uint8_t> bytes = std::move(result).value();
-  auto deser = fory.deserialize<BoundingBox>(bytes.data(), bytes.size());
-  ASSERT_TRUE(deser.ok());
-  EXPECT_EQ(bb, deser.value());
-}
-
 TEST(StructComprehensiveTest, LargeVectorOfStructs) {
   std::vector<Point2D> points;
   for (int i = 0; i < 1000; ++i) {


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to