This is an automated email from the ASF dual-hosted git repository.
wgtmac pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/iceberg-cpp.git
The following commit(s) were added to refs/heads/main by this push:
new ba5e7ce7 fix: reject malformed commit property integers (#843)
ba5e7ce7 is described below
commit ba5e7ce792b19c66f7a882bba12700a25d3687e9
Author: Minh Vu <[email protected]>
AuthorDate: Mon Aug 3 05:51:09 2026 +0200
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)
---
src/iceberg/test/table_metadata_builder_test.cc | 16 ++++++++++++++++
src/iceberg/util/property_util.cc | 13 +++++--------
2 files changed, 21 insertions(+), 8 deletions(-)
diff --git a/src/iceberg/test/table_metadata_builder_test.cc
b/src/iceberg/test/table_metadata_builder_test.cc
index 5fd970d6..0d10722b 100644
--- a/src/iceberg/test/table_metadata_builder_test.cc
+++ b/src/iceberg/test/table_metadata_builder_test.cc
@@ -200,6 +200,22 @@ TEST(TableMetadataTest, InvalidProperties) {
"Table property {} must have non negative integer value,
but got {}",
TableProperties::kCommitNumRetries.key(), -1)));
}
+
+ {
+ // Commit properties must contain only an integer, not a valid integer
prefix.
+ ICEBERG_UNWRAP_OR_FAIL(auto schema, CreateDisorderedSchema());
+ for (const auto& value : {"4x", "1.5"}) {
+ std::unordered_map<std::string, std::string> invalid_commit_properties =
{
+ {TableProperties::kCommitNumRetries.key(), value}};
+
+ auto res = TableMetadata::Make(*schema, *spec, *order,
"s3://bucket/test",
+ invalid_commit_properties);
+ EXPECT_THAT(res, IsError(ErrorKind::kValidationFailed));
+ EXPECT_THAT(res, HasErrorMessage(std::format(
+ "Table property {} must have integer value, but got
{}",
+ TableProperties::kCommitNumRetries.key(), value)));
+ }
+ }
}
// test construction of TableMetadataBuilder
diff --git a/src/iceberg/util/property_util.cc
b/src/iceberg/util/property_util.cc
index 636083fd..32d9e3ba 100644
--- a/src/iceberg/util/property_util.cc
+++ b/src/iceberg/util/property_util.cc
@@ -19,9 +19,10 @@
#include "iceberg/util/property_util.h"
-#include <charconv>
+#include <cstdint>
#include "iceberg/table_properties.h"
+#include "iceberg/util/string_util.h"
namespace iceberg {
@@ -29,16 +30,12 @@ Status PropertyUtil::ValidateCommitProperties(
const std::unordered_map<std::string, std::string>& properties) {
for (const auto& property : TableProperties::commit_properties()) {
if (auto it = properties.find(property); it != properties.end()) {
- int32_t parsed;
- auto [ptr, ec] = std::from_chars(it->second.data(),
- it->second.data() + it->second.size(),
parsed);
- if (ec == std::errc::invalid_argument) {
+ auto parsed_result = StringUtils::ParseNumber<int32_t>(it->second);
+ if (!parsed_result) {
return ValidationFailed("Table property {} must have integer value,
but got {}",
property, it->second);
- } else if (ec == std::errc::result_out_of_range) {
- return ValidationFailed("Table property {} value out of range {}",
property,
- it->second);
}
+ const auto parsed = *parsed_result;
if (parsed < 0) {
return ValidationFailed(
"Table property {} must have non negative integer value, but got
{}",