Skip to content

Commit ba5e7ce

Browse files
fix: reject malformed commit property integers (#843)
## Summary - require commit property integers to parse completely, matching Java's `Integer.parseInt` - reject values with alphanumeric or decimal suffixes instead of accepting their numeric prefix - preserve the existing validation errors for invalid and out-of-range values ## Testing - `ctest --test-dir build -R ^table_test$ --output-on-failure` - full CTest suite (17 test binaries)
1 parent f3fa485 commit ba5e7ce

2 files changed

Lines changed: 21 additions & 8 deletions

File tree

src/iceberg/test/table_metadata_builder_test.cc

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,22 @@ TEST(TableMetadataTest, InvalidProperties) {
200200
"Table property {} must have non negative integer value, but got {}",
201201
TableProperties::kCommitNumRetries.key(), -1)));
202202
}
203+
204+
{
205+
// Commit properties must contain only an integer, not a valid integer prefix.
206+
ICEBERG_UNWRAP_OR_FAIL(auto schema, CreateDisorderedSchema());
207+
for (const auto& value : {"4x", "1.5"}) {
208+
std::unordered_map<std::string, std::string> invalid_commit_properties = {
209+
{TableProperties::kCommitNumRetries.key(), value}};
210+
211+
auto res = TableMetadata::Make(*schema, *spec, *order, "s3://bucket/test",
212+
invalid_commit_properties);
213+
EXPECT_THAT(res, IsError(ErrorKind::kValidationFailed));
214+
EXPECT_THAT(res, HasErrorMessage(std::format(
215+
"Table property {} must have integer value, but got {}",
216+
TableProperties::kCommitNumRetries.key(), value)));
217+
}
218+
}
203219
}
204220

205221
// test construction of TableMetadataBuilder

src/iceberg/util/property_util.cc

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,26 +19,23 @@
1919

2020
#include "iceberg/util/property_util.h"
2121

22-
#include <charconv>
22+
#include <cstdint>
2323

2424
#include "iceberg/table_properties.h"
25+
#include "iceberg/util/string_util.h"
2526

2627
namespace iceberg {
2728

2829
Status PropertyUtil::ValidateCommitProperties(
2930
const std::unordered_map<std::string, std::string>& properties) {
3031
for (const auto& property : TableProperties::commit_properties()) {
3132
if (auto it = properties.find(property); it != properties.end()) {
32-
int32_t parsed;
33-
auto [ptr, ec] = std::from_chars(it->second.data(),
34-
it->second.data() + it->second.size(), parsed);
35-
if (ec == std::errc::invalid_argument) {
33+
auto parsed_result = StringUtils::ParseNumber<int32_t>(it->second);
34+
if (!parsed_result) {
3635
return ValidationFailed("Table property {} must have integer value, but got {}",
3736
property, it->second);
38-
} else if (ec == std::errc::result_out_of_range) {
39-
return ValidationFailed("Table property {} value out of range {}", property,
40-
it->second);
4137
}
38+
const auto parsed = *parsed_result;
4239
if (parsed < 0) {
4340
return ValidationFailed(
4441
"Table property {} must have non negative integer value, but got {}",

0 commit comments

Comments
 (0)