You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "ArnavBalyan (via GitHub)" <gi...@apache.org> on 2026/03/29 05:46:26 UTC
[PR] GH-47657: [C++][Parquet] Check for integer overflow when coercing timestamps [arrow]
ArnavBalyan opened a new pull request, #49615:
URL: https://github.com/apache/arrow/pull/49615
### Rationale for this change
- When writing Arrow timestamps to Parquet, timestamp values are multiplied to convert units
- This multiplication was performed without overflow checking which can silently write corrupt data.
### What changes are included in this PR?
- Use MultiplyWithOverflowGeneric to handle/detect overflow
### Are these changes tested?
- Yes
### Are there any user-facing changes?
- Yes
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GH-47657: [C++][Parquet] Check for integer overflow when coercing timestamps [arrow]
Posted by "wgtmac (via GitHub)" <gi...@apache.org>.
wgtmac merged PR #49615:
URL: https://github.com/apache/arrow/pull/49615
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GH-47657: [C++][Parquet] Check for integer overflow when coercing timestamps [arrow]
Posted by "wgtmac (via GitHub)" <gi...@apache.org>.
wgtmac commented on code in PR #49615:
URL: https://github.com/apache/arrow/pull/49615#discussion_r3010290792
##########
cpp/src/parquet/arrow/arrow_reader_writer_test.cc:
##########
@@ -2178,6 +2178,53 @@ TEST(TestArrowReadWrite, ImplicitSecondToMillisecondTimestampCoercion) {
ASSERT_NO_FATAL_FAILURE(::arrow::AssertTablesEqual(*tx, *to));
}
+TEST(TestArrowReadWrite, TimestampCoercionOverflow) {
+ using ::arrow::ArrayFromVector;
+ using ::arrow::field;
+ using ::arrow::schema;
+
+ auto t_s = ::arrow::timestamp(TimeUnit::SECOND);
+
+ std::vector<int64_t> overflow_values = {9223372036854776LL};
+ std::vector<bool> is_valid = {true};
+
+ std::shared_ptr<Array> a_s;
+ ArrayFromVector<::arrow::TimestampType, int64_t>(t_s, is_valid, overflow_values, &a_s);
+
+ auto s = schema({field("timestamp", t_s)});
+ auto table = Table::Make(s, {a_s});
+
+ ASSERT_RAISES(Invalid, WriteTable(*table, ::arrow::default_memory_pool(),
+ CreateOutputStream(), table->num_rows()));
+
+ auto coerce_millis =
Review Comment:
Lines below have some duplications. Can we use a for loop on TimeUnit to reduce them?
##########
cpp/src/parquet/column_writer.cc:
##########
@@ -2352,7 +2353,13 @@ struct SerializeFunctor<Int64Type, ::arrow::TimestampType> {
auto MultiplyBy = [&](const int64_t factor) {
for (int64_t i = 0; i < array.length(); i++) {
- out[i] = values[i] * factor;
+ if (ARROW_PREDICT_FALSE(::arrow::internal::MultiplyWithOverflowGeneric(
+ values[i], factor, &out[i])) &&
+ array.IsValid(i)) {
Review Comment:
It would be better to reorder `array.IsValid(i)` and `MultiplyWithOverflowGeneric`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GH-47657: [C++][Parquet] Check for integer overflow when coercing timestamps [arrow]
Posted by "ArnavBalyan (via GitHub)" <gi...@apache.org>.
ArnavBalyan commented on PR #49615:
URL: https://github.com/apache/arrow/pull/49615#issuecomment-4318399540
Thanks @wgtmac! Could this be merged
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GH-47657: [C++][Parquet] Check for integer overflow when coercing timestamps [arrow]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #49615:
URL: https://github.com/apache/arrow/pull/49615#issuecomment-4149500452
:warning: GitHub issue #47657 **has been automatically assigned in GitHub** to PR creator.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GH-47657: [C++][Parquet] Check for integer overflow when coercing timestamps [arrow]
Posted by "ArnavBalyan (via GitHub)" <gi...@apache.org>.
ArnavBalyan commented on PR #49615:
URL: https://github.com/apache/arrow/pull/49615#issuecomment-4341593901
Thanks @wgtmac!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GH-47657: [C++][Parquet] Check for integer overflow when coercing timestamps [arrow]
Posted by "wgtmac (via GitHub)" <gi...@apache.org>.
wgtmac commented on PR #49615:
URL: https://github.com/apache/arrow/pull/49615#issuecomment-4341585850
Merged. Thanks @ArnavBalyan!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GH-47657: [C++][Parquet] Check for integer overflow when coercing timestamps [arrow]
Posted by "conbench-apache-arrow[bot] (via GitHub)" <gi...@apache.org>.
conbench-apache-arrow[bot] commented on PR #49615:
URL: https://github.com/apache/arrow/pull/49615#issuecomment-4341900736
After merging your PR, Conbench analyzed the 0 benchmarking runs that have been run so far on merge-commit b3dcb6d63b4ea698e6a8fcc00f3fd73d3e25071b.
None of the specified runs were found on the Conbench server.
The [full Conbench report](https://github.com/apache/arrow/runs/73538664533) has more details.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GH-47657: [C++][Parquet] Check for integer overflow when coercing timestamps [arrow]
Posted by "ArnavBalyan (via GitHub)" <gi...@apache.org>.
ArnavBalyan commented on code in PR #49615:
URL: https://github.com/apache/arrow/pull/49615#discussion_r3011668361
##########
cpp/src/parquet/column_writer.cc:
##########
@@ -2352,7 +2353,13 @@ struct SerializeFunctor<Int64Type, ::arrow::TimestampType> {
auto MultiplyBy = [&](const int64_t factor) {
for (int64_t i = 0; i < array.length(); i++) {
- out[i] = values[i] * factor;
+ if (ARROW_PREDICT_FALSE(::arrow::internal::MultiplyWithOverflowGeneric(
+ values[i], factor, &out[i])) &&
+ array.IsValid(i)) {
Review Comment:
done thanks
##########
cpp/src/parquet/arrow/arrow_reader_writer_test.cc:
##########
@@ -2178,6 +2178,53 @@ TEST(TestArrowReadWrite, ImplicitSecondToMillisecondTimestampCoercion) {
ASSERT_NO_FATAL_FAILURE(::arrow::AssertTablesEqual(*tx, *to));
}
+TEST(TestArrowReadWrite, TimestampCoercionOverflow) {
+ using ::arrow::ArrayFromVector;
+ using ::arrow::field;
+ using ::arrow::schema;
+
+ auto t_s = ::arrow::timestamp(TimeUnit::SECOND);
+
+ std::vector<int64_t> overflow_values = {9223372036854776LL};
+ std::vector<bool> is_valid = {true};
+
+ std::shared_ptr<Array> a_s;
+ ArrayFromVector<::arrow::TimestampType, int64_t>(t_s, is_valid, overflow_values, &a_s);
+
+ auto s = schema({field("timestamp", t_s)});
+ auto table = Table::Make(s, {a_s});
+
+ ASSERT_RAISES(Invalid, WriteTable(*table, ::arrow::default_memory_pool(),
+ CreateOutputStream(), table->num_rows()));
+
+ auto coerce_millis =
Review Comment:
updated
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GH-47657: [C++][Parquet] Check for integer overflow when coercing timestamps [arrow]
Posted by "wgtmac (via GitHub)" <gi...@apache.org>.
wgtmac commented on code in PR #49615:
URL: https://github.com/apache/arrow/pull/49615#discussion_r3013242986
##########
cpp/src/parquet/arrow/arrow_reader_writer_test.cc:
##########
@@ -2178,6 +2178,45 @@ TEST(TestArrowReadWrite, ImplicitSecondToMillisecondTimestampCoercion) {
ASSERT_NO_FATAL_FAILURE(::arrow::AssertTablesEqual(*tx, *to));
}
+TEST(TestArrowReadWrite, TimestampCoercionOverflow) {
+ using ::arrow::ArrayFromVector;
+ using ::arrow::field;
+ using ::arrow::schema;
+
+ auto t_s = ::arrow::timestamp(TimeUnit::SECOND);
+
+ std::vector<int64_t> overflow_values = {9223372036854776LL};
+ std::vector<bool> is_valid = {true};
+
+ std::shared_ptr<Array> a_s;
+ ArrayFromVector<::arrow::TimestampType, int64_t>(t_s, is_valid, overflow_values, &a_s);
+
+ auto s = schema({field("timestamp", t_s)});
+ auto table = Table::Make(s, {a_s});
+
+ ASSERT_RAISES(Invalid, WriteTable(*table, default_memory_pool(),
Review Comment:
It seems that this check can also be merged to the for loop by checking if the TimeUint is `TimeUnit::SECOND` and then skips `coerce_timestamps`?
##########
cpp/src/parquet/arrow/arrow_reader_writer_test.cc:
##########
@@ -2178,6 +2178,45 @@ TEST(TestArrowReadWrite, ImplicitSecondToMillisecondTimestampCoercion) {
ASSERT_NO_FATAL_FAILURE(::arrow::AssertTablesEqual(*tx, *to));
}
+TEST(TestArrowReadWrite, TimestampCoercionOverflow) {
+ using ::arrow::ArrayFromVector;
+ using ::arrow::field;
+ using ::arrow::schema;
+
+ auto t_s = ::arrow::timestamp(TimeUnit::SECOND);
+
+ std::vector<int64_t> overflow_values = {9223372036854776LL};
+ std::vector<bool> is_valid = {true};
+
+ std::shared_ptr<Array> a_s;
+ ArrayFromVector<::arrow::TimestampType, int64_t>(t_s, is_valid, overflow_values, &a_s);
+
+ auto s = schema({field("timestamp", t_s)});
+ auto table = Table::Make(s, {a_s});
+
+ ASSERT_RAISES(Invalid, WriteTable(*table, default_memory_pool(),
+ CreateOutputStream(), table->num_rows()));
+
+ for (auto unit : {TimeUnit::MILLI, TimeUnit::MICRO, TimeUnit::NANO}) {
+ auto coerce_props =
+ ArrowWriterProperties::Builder().coerce_timestamps(unit)->build();
+ ASSERT_RAISES(
+ Invalid,
+ WriteTable(*table, default_memory_pool(), CreateOutputStream(),
+ table->num_rows(), default_writer_properties(),
+ coerce_props));
+ }
+
+ std::vector<int64_t> null_overflow_values = {9223372036854776LL};
+ std::vector<bool> null_valid = {false};
+ std::shared_ptr<Array> a_null;
+ ArrayFromVector<::arrow::TimestampType, int64_t>(t_s, null_valid, null_overflow_values,
Review Comment:
```suggestion
std::vector<bool> null_valid = {false};
std::shared_ptr<Array> a_null;
ArrayFromVector<::arrow::TimestampType, int64_t>(t_s, null_valid, overflow_values,
```
##########
cpp/src/parquet/arrow/arrow_reader_writer_test.cc:
##########
@@ -2178,6 +2178,45 @@ TEST(TestArrowReadWrite, ImplicitSecondToMillisecondTimestampCoercion) {
ASSERT_NO_FATAL_FAILURE(::arrow::AssertTablesEqual(*tx, *to));
}
+TEST(TestArrowReadWrite, TimestampCoercionOverflow) {
+ using ::arrow::ArrayFromVector;
+ using ::arrow::field;
+ using ::arrow::schema;
+
+ auto t_s = ::arrow::timestamp(TimeUnit::SECOND);
+
+ std::vector<int64_t> overflow_values = {9223372036854776LL};
+ std::vector<bool> is_valid = {true};
+
+ std::shared_ptr<Array> a_s;
+ ArrayFromVector<::arrow::TimestampType, int64_t>(t_s, is_valid, overflow_values, &a_s);
+
+ auto s = schema({field("timestamp", t_s)});
+ auto table = Table::Make(s, {a_s});
+
+ ASSERT_RAISES(Invalid, WriteTable(*table, default_memory_pool(),
+ CreateOutputStream(), table->num_rows()));
+
+ for (auto unit : {TimeUnit::MILLI, TimeUnit::MICRO, TimeUnit::NANO}) {
+ auto coerce_props =
+ ArrowWriterProperties::Builder().coerce_timestamps(unit)->build();
+ ASSERT_RAISES(
+ Invalid,
+ WriteTable(*table, default_memory_pool(), CreateOutputStream(),
+ table->num_rows(), default_writer_properties(),
+ coerce_props));
+ }
+
+ std::vector<int64_t> null_overflow_values = {9223372036854776LL};
+ std::vector<bool> null_valid = {false};
+ std::shared_ptr<Array> a_null;
+ ArrayFromVector<::arrow::TimestampType, int64_t>(t_s, null_valid, null_overflow_values,
Review Comment:
It looks unnecessary to use `null_overflow_values`
##########
cpp/src/parquet/arrow/arrow_reader_writer_test.cc:
##########
@@ -2178,6 +2178,45 @@ TEST(TestArrowReadWrite, ImplicitSecondToMillisecondTimestampCoercion) {
ASSERT_NO_FATAL_FAILURE(::arrow::AssertTablesEqual(*tx, *to));
}
+TEST(TestArrowReadWrite, TimestampCoercionOverflow) {
+ using ::arrow::ArrayFromVector;
+ using ::arrow::field;
+ using ::arrow::schema;
+
+ auto t_s = ::arrow::timestamp(TimeUnit::SECOND);
+
+ std::vector<int64_t> overflow_values = {9223372036854776LL};
+ std::vector<bool> is_valid = {true};
+
+ std::shared_ptr<Array> a_s;
+ ArrayFromVector<::arrow::TimestampType, int64_t>(t_s, is_valid, overflow_values, &a_s);
Review Comment:
```suggestion
auto t_s = ::arrow::timestamp(TimeUnit::SECOND);
std::vector<int64_t> overflow_values = {9223372036854776LL};
std::vector<bool> is_valid = {true};
std::shared_ptr<Array> a_s;
ArrayFromVector<::arrow::TimestampType, int64_t>(t_s, is_valid, overflow_values, &a_s);
```
Let's remove these blank lines to be consistent with lines after 2210?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GH-47657: [C++][Parquet] Check for integer overflow when coercing timestamps [arrow]
Posted by "conbench-apache-arrow[bot] (via GitHub)" <gi...@apache.org>.
conbench-apache-arrow[bot] commented on PR #49615:
URL: https://github.com/apache/arrow/pull/49615#issuecomment-4446182529
After merging your PR, Conbench analyzed the 2 benchmarking runs that have been run so far on merge-commit b3dcb6d63b4ea698e6a8fcc00f3fd73d3e25071b.
There were no benchmark performance regressions. 🎉
The [full Conbench report](https://github.com/apache/arrow/runs/75904073758) has more details.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org