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 2022/10/15 10:31:51 UTC

[GitHub] [arrow-datafusion] alamb commented on a diff in pull request #3829: Fix the panic when lpad/rpad parameter is negative

alamb commented on code in PR #3829:
URL: https://github.com/apache/arrow-datafusion/pull/3829#discussion_r996287002


##########
datafusion/physical-expr/src/unicode_expressions.rs:
##########
@@ -262,24 +273,29 @@ pub fn rpad<T: OffsetSizeTrait>(args: &[ArrayRef]) -> Result<ArrayRef> {
                 .zip(length_array.iter())
                 .map(|(string, length)| match (string, length) {
                     (Some(string), Some(length)) => {
-                        let length = length as usize;
+                        if length > i32::MAX as i64 {
+                            return Err(DataFusionError::Internal(
+                                "lpad requested length too large".to_string(),

Review Comment:
   ```suggestion
                                   format!("rpad requested length {} too large", length),
   ```



##########
datafusion/physical-expr/src/unicode_expressions.rs:
##########
@@ -293,14 +309,20 @@ pub fn rpad<T: OffsetSizeTrait>(args: &[ArrayRef]) -> Result<ArrayRef> {
                 .zip(fill_array.iter())
                 .map(|((string, length), fill)| match (string, length, fill) {
                     (Some(string), Some(length), Some(fill)) => {
-                        let length = length as usize;
+                        if length > i32::MAX as i64 {
+                            return Err(DataFusionError::Internal(
+                                "lpad requested length too large".to_string(),

Review Comment:
   ```suggestion
                                   format!("rpad requested length {} too large", length),
   ```



##########
datafusion/physical-expr/src/unicode_expressions.rs:
##########
@@ -160,18 +166,23 @@ pub fn lpad<T: OffsetSizeTrait>(args: &[ArrayRef]) -> Result<ArrayRef> {
                 .zip(fill_array.iter())
                 .map(|((string, length), fill)| match (string, length, fill) {
                     (Some(string), Some(length), Some(fill)) => {
-                        let length = length as usize;
+                        if length > i32::MAX as i64 {
+                            return Err(DataFusionError::Internal(
+                                "lpad requested length too large".to_string(),

Review Comment:
   ```suggestion
                                   format!("lpad requested length {} too large", length),
   ```



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org