You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2020/08/20 11:43:52 UTC

[GitHub] [arrow] pitrou commented on a change in pull request #7987: ARROW-9768: [Python] Check overflow in conversion of datetime objects to nanosecond timestamps

pitrou commented on a change in pull request #7987:
URL: https://github.com/apache/arrow/pull/7987#discussion_r473907662



##########
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:
       This subtraction could overflow as well, no?




----------------------------------------------------------------
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:
users@infra.apache.org