Fix the panic when lpad/rpad parameter is negative#3829
Conversation
|
@alamb could you review? |
| let length = length as usize; | ||
| if length > i32::MAX as i64 { | ||
| return Err(DataFusionError::Internal( | ||
| "lpad requested length too large".to_string(), |
There was a problem hiding this comment.
| "lpad requested length too large".to_string(), | |
| "rpad requested length too large".to_string(), |
There was a problem hiding this comment.
| "lpad requested length too large".to_string(), | |
| format!("rpad requested length {} too large", length), |
| let length = length as usize; | ||
| if length > i32::MAX as i64 { | ||
| return Err(DataFusionError::Internal( | ||
| "lpad requested length too large".to_string(), |
There was a problem hiding this comment.
| "lpad requested length too large".to_string(), | |
| "rpad requested length too large".to_string(), |
There was a problem hiding this comment.
| "lpad requested length too large".to_string(), | |
| format!("rpad requested length {} too large", length), |
| let length = length as usize; | ||
| if length > i32::MAX as i64 { | ||
| return Err(DataFusionError::Internal( | ||
| "lpad requested length too large".to_string(), |
There was a problem hiding this comment.
| "lpad requested length too large".to_string(), | |
| format!("lpad requested length {} too large", length), |
| let length = length as usize; | ||
| if length > i32::MAX as i64 { | ||
| return Err(DataFusionError::Internal( | ||
| "lpad requested length too large".to_string(), |
There was a problem hiding this comment.
| "lpad requested length too large".to_string(), | |
| format!("rpad requested length {} too large", length), |
| let length = length as usize; | ||
| if length > i32::MAX as i64 { | ||
| return Err(DataFusionError::Internal( | ||
| "lpad requested length too large".to_string(), |
There was a problem hiding this comment.
| "lpad requested length too large".to_string(), | |
| format!("rpad requested length {} too large", length), |
* fix the panic when lpad/rpad parameter is negative * add lpad/rpad test
|
Benchmark runs are scheduled for baseline = 431a412 and contender = aec240f. aec240f is a master commit associated with this PR. Results will be available as each benchmark for each run completes. |
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'.
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
ERROR: requested length too large
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