diff --git a/src/iceberg/json_serde.cc b/src/iceberg/json_serde.cc index c1c3ffb73..3418d4837 100644 --- a/src/iceberg/json_serde.cc +++ b/src/iceberg/json_serde.cc @@ -853,6 +853,9 @@ Result> TypeFromJson(const nlohmann::json& json) { StringUtils::ParseNumber(match[1].str())); ICEBERG_ASSIGN_OR_RAISE(auto scale, StringUtils::ParseNumber(match[2].str())); + if (precision > DecimalType::kMaxPrecision) { + return JsonParseError("Invalid decimal type: {}", type_name); + } return std::make_unique(precision, scale); } return JsonParseError("Invalid decimal type: {}", type_name); diff --git a/src/iceberg/test/schema_json_test.cc b/src/iceberg/test/schema_json_test.cc index f90a0c2ca..4930d40bf 100644 --- a/src/iceberg/test/schema_json_test.cc +++ b/src/iceberg/test/schema_json_test.cc @@ -103,6 +103,13 @@ INSTANTIATE_TEST_SUITE_P( SchemaField::MakeRequired(1, "id", iceberg::int32()), SchemaField::MakeOptional(2, "name", iceberg::string())})})); +TEST(TypeJsonTest, FromJsonOutOfRangeDecimalPrecisionIsParseError) { + // Precision beyond the supported maximum must surface as a parse error, + // not an uncaught IcebergError from the DecimalType constructor. + auto result = TypeFromJson(nlohmann::json::parse("\"decimal(39, 2)\"")); + EXPECT_THAT(result, IsError(ErrorKind::kJsonParseError)); +} + TEST(TypeJsonTest, FromJsonWithSpaces) { auto fixed_json = R"("fixed[ 8 ]")"; auto fixed_result = TypeFromJson(nlohmann::json::parse(fixed_json));