-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"lpad requested length too large".to_string(), | |
"rpad requested length too large".to_string(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"lpad requested length too large".to_string(), | |
"rpad requested length too large".to_string(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"lpad requested length too large".to_string(), | |
format!("rpad requested length {} too large", length), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is looking great -- thank you @ZuoTiJia
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great -- thanks @ZuoTiJia
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Thanks @ZuoTiJia
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