jorisvandenbossche commented on a change in pull request #7987:
URL: https://github.com/apache/arrow/pull/7987#discussion_r473911916
##########
File path: cpp/src/arrow/python/python_to_arrow.cc
##########
@@ -263,7 +264,12 @@ struct ValueConverter<TimestampType> {
value = internal::PyDateTime_to_us(dt) - offset * 1000 * 1000;
break;
case TimeUnit::NANO:
- value = internal::PyDateTime_to_ns(dt) - offset * 1000 * 1000 * 1000;
+ // Conversion to nanoseconds can overflow -> check multiply of
microseconds
+ value = internal::PyDateTime_to_us(dt);
+ if (arrow::internal::MultiplyWithOverflow(value, 1000, &value)) {
+ return internal::InvalidValue(obj, "out of bounds for nanosecond
resolution");
+ }
+ value -= offset * 1000 * 1000 * 1000;
Review comment:
Ah, the offset itself won't overflow, but for the *subtraction* (as you
actually commented ..) that could indeed happen in a small corner case: if your
naive timezone is close to the lower or upper limit of the nanosecond range,
applying the offset could indeed overflow.
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]