Uploaded image for project: 'Apache Arrow'
  1. Apache Arrow
  2. ARROW-3790

[C++] Signed to unsigned integer cast yields incorrect results when type sizes are the same

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • None
    • 0.12.0
    • C++

    Description

      In https://github.com/apache/arrow/blob/master/cpp/src/arrow/compute/kernels/cast.cc#L239, an int32_t is overflows in

      constexpr in_type kMax = static_cast<in_type>(std::numeric_limits<out_type>::max());
      

      resulting in safety checks not being correctly performed

      In [2]: arr = pa.array([-1, -2, -3], type='int32')
      
      In [3]: arr.cast('uint32')
      Out[3]: 
      <pyarrow.lib.UInt32Array object at 0x7f4889457b88>
      [
        4294967295,
        4294967294,
        4294967293
      ]
      

      This would be expected to error when safe=True

      Attachments

        Issue Links

          Activity

            People

              fsaintjacques Francois Saint-Jacques
              wesm Wes McKinney
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 3.5h
                  3.5h