ZuoTiJia opened a new pull request, #3829:
URL: https://github.com/apache/arrow-datafusion/pull/3829

   When I pass a negative parameter to the lpad function, it panics. Because 
the function will cast i64 to usize, which causes Vec to be unable to allocate 
enough memory, resulting in 'panic: capacity overflow'.
   
   ```shell
   DataFusion CLI v13.0.0
   ❯ select lpad('abc', -1, 'abc');
   thread 'main' panicked at 'capacity overflow', 
library/alloc/src/raw_vec.rs:518:5
   ```
   
   I refer to the implementation of postgres, in postges, length is limited to 
i32, too large length will throw an error.
   
   In psql 14.5
   ```sql
   SELECT lpad('abc', 2147483647, 'abc');
   ```
   ERROR:  requested length too large
   ```sql
   SELECT lpad('abc', -1);
   ```
    lpad
   ------
   
   (1 row)
   
   
   At first I changed the function signature.
   
   But after I changed the function signature, calling this function requires 
troublesome cast.
   
   
   
   # What changes are included in this PR?
   So I can only change the inside of the function
   
   if length < 0 length = 0;
   
   if length > i32::MAX, an Error will be thrown
   
   


-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to