Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/Storages/ObjectStorage/DataLakes/DeltaLakeMetadata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include <Storages/ObjectStorage/DataLakes/DeltaLakeMetadata.h>
#include <Storages/ObjectStorage/Utils.h>
#include <base/JSON.h>
#include <Core/Defines.h>
#include "config.h"

#if USE_PARQUET
Expand Down Expand Up @@ -260,6 +261,9 @@ struct DeltaLakeMetadataImpl
continue;

Poco::JSON::Parser parser;
/// Bound the parser depth so a deeply nested metadata/schema JSON is rejected cleanly
/// instead of overflowing the native stack in Poco's recursive parser.
parser.setDepth(DBMS_DEFAULT_MAX_PARSER_DEPTH);
Poco::Dynamic::Var json = parser.parse(json_str);
const Poco::JSON::Object::Ptr & object = json.extract<Poco::JSON::Object::Ptr>();

Expand Down Expand Up @@ -540,6 +544,7 @@ struct DeltaLakeMetadataImpl
if (!metadata.empty())
{
Poco::JSON::Parser parser;
parser.setDepth(DBMS_DEFAULT_MAX_PARSER_DEPTH);
Poco::Dynamic::Var json = parser.parse(metadata);
const Poco::JSON::Object::Ptr & object = json.extract<Poco::JSON::Object::Ptr>();

Expand Down
4 changes: 4 additions & 0 deletions src/Storages/ObjectStorage/DataLakes/Iceberg/ManifestFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

#include <Core/TypeId.h>
#include <DataTypes/DataTypesDecimal.h>
#include <Core/Defines.h>
#include <Poco/JSON/Parser.h>
#include <Storages/ColumnsDescription.h>
#include <Parsers/ASTFunction.h>
Expand Down Expand Up @@ -175,6 +176,9 @@ ManifestFileContent::ManifestFileContent(
ErrorCodes::ICEBERG_SPECIFICATION_VIOLATION, "Required columns are not found in manifest file: {}", f_sequence_number);

Poco::JSON::Parser parser;
/// Bound the parser depth so deeply nested partition-spec/schema JSON is rejected cleanly
/// instead of overflowing the native stack in Poco's recursive parser.
parser.setDepth(DBMS_DEFAULT_MAX_PARSER_DEPTH);

auto partition_spec_json_string = manifest_file_deserializer.tryGetAvroMetadataValue("partition-spec");
if (!partition_spec_json_string.has_value())
Expand Down
4 changes: 4 additions & 0 deletions src/Storages/ObjectStorage/DataLakes/Iceberg/Utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <Storages/ColumnsDescription.h>
#include <base/types.h>
#include <Core/ColumnsWithTypeAndName.h>
#include <Core/Defines.h>
#include <Storages/ObjectStorage/DataLakes/Iceberg/IcebergWrites.h>
#include <config.h>

Expand Down Expand Up @@ -300,6 +301,9 @@ Poco::JSON::Object::Ptr getMetadataJSONObject(
metadata_json_str = create_fn();

Poco::JSON::Parser parser; /// For some reason base/base/JSON.h can not parse this json file
/// Bound the parser depth so a deeply nested (attacker-controlled) metadata JSON is rejected
/// cleanly instead of overflowing the native stack in Poco's recursive parser.
parser.setDepth(DBMS_DEFAULT_MAX_PARSER_DEPTH);
Poco::Dynamic::Var json = parser.parse(metadata_json_str);
return json.extract<Poco::JSON::Object::Ptr>();
}
Expand Down
Loading