This is an automated email from the ASF dual-hosted git repository.

github-merge-queue[bot] pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow-rs.git


The following commit(s) were added to refs/heads/main by this push:
     new 32902415b8 fix(parquet): return error for out-of-range FLBA dictionary 
index (#12065)
32902415b8 is described below

commit 32902415b841ac824470d8ee9ffd4b785d8b2a9a
Author: linzch3 <[email protected]>
AuthorDate: Thu Nov 5 00:06:41 2026 +0000

    fix(parquet): return error for out-of-range FLBA dictionary index (#12065)
    
    # Which issue does this PR close?
    
    - Closes #11689.
    
    # Rationale for this change
    
    A corrupt FIXED_LEN_BYTE_ARRAY column with a dictionary index past the
    end of the dictionary panics with a slice-out-of-range error instead of
    returning a `ParquetError`.
    
    # What changes are included in this PR?
    
    In the dictionary path of the FLBA `ValueDecoder::read`, each key is
    checked against the number of dictionary entries before slicing. The
    error message is the same one `RleDecoder::get_batch_with_dict` already
    uses for other types. Negative keys become huge values after `as usize`,
    so the same check catches them.
    
    AI disclosure: the fix and test were prepared with an AI coding
    assistant. The test was run locally with and without the fix. I've also
    reviewed the changes myself.
    
    # Are these changes tested?
    
    Yes. `test_dictionary_index_out_of_bounds` builds a 2-entry FLBA
    dictionary and an RLE page that refers to index 2. It panicked before
    this change and now returns the error.
    
    # Are there any significant user-facing changes?
    
    No.
    
    Co-authored-by: linzch3 <[email protected]>
---
 .../src/arrow/array_reader/fixed_len_byte_array.rs | 51 +++++++++++++++++++++-
 1 file changed, 50 insertions(+), 1 deletion(-)

diff --git a/parquet/src/arrow/array_reader/fixed_len_byte_array.rs 
b/parquet/src/arrow/array_reader/fixed_len_byte_array.rs
index e81e4dec70..49ded4bf4e 100644
--- a/parquet/src/arrow/array_reader/fixed_len_byte_array.rs
+++ b/parquet/src/arrow/array_reader/fixed_len_byte_array.rs
@@ -451,10 +451,19 @@ impl ValueDecoder {
                     return Ok(0);
                 }
 
+                let dict_len = dict.len() / self.byte_length;
                 decoder.read(num_values, |keys| {
                     out.reserve(keys.len() * self.byte_length);
                     for key in keys {
-                        let offset = *key as usize * self.byte_length;
+                        let index = *key as usize;
+                        if index >= dict_len {
+                            return Err(general_err!(
+                                "dictionary index out of bounds: the len is {} 
but the index is {}",
+                                dict_len,
+                                key
+                            ));
+                        }
+                        let offset = index * self.byte_length;
                         out.extend_from_slice(&dict.as_ref()[offset..offset + 
self.byte_length]);
                     }
                     Ok(())
@@ -639,6 +648,7 @@ mod tests {
     };
     use crate::data_type::{FixedLenByteArray, FixedLenByteArrayType};
     use crate::file::writer::SerializedFileWriter;
+    use crate::schema::types::{ColumnDescriptor, ColumnPath};
     use arrow::datatypes::{Field, Schema};
     use arrow::error::Result as ArrowResult;
     use arrow_array::{Array, ListArray};
@@ -658,6 +668,45 @@ mod tests {
         assert_eq!(buffer.values_capacity, Some(12));
     }
 
+    #[test]
+    fn test_dictionary_index_out_of_bounds() {
+        let t = crate::schema::types::Type::primitive_type_builder(
+            "col",
+            crate::basic::Type::FIXED_LEN_BYTE_ARRAY,
+        )
+        .with_length(4)
+        .build()
+        .unwrap();
+        let column_desc = Arc::new(ColumnDescriptor::new(
+            Arc::new(t),
+            0,
+            0,
+            ColumnPath::new(vec![]),
+        ));
+        let mut decoder = ValueDecoder::new(&column_desc);
+        decoder
+            .set_dict(
+                Bytes::from_static(b"aaaabbbb"),
+                2,
+                Encoding::PLAIN_DICTIONARY,
+                false,
+            )
+            .unwrap();
+
+        // Bit width 8, then an RLE run of one value with dictionary index 2
+        let page = Bytes::from_static(&[8, 0b10, 2]);
+        decoder
+            .set_data(Encoding::RLE_DICTIONARY, page, 1, Some(1))
+            .unwrap();
+
+        let mut output = FixedLenByteArrayBuffer::with_capacity(4);
+        let err = decoder.read(&mut output, 1).unwrap_err();
+        assert_eq!(
+            err.to_string(),
+            "Parquet error: dictionary index out of bounds: the len is 2 but 
the index is 2"
+        );
+    }
+
     #[test]
     fn test_decimal_list() {
         let decimals = Decimal256Array::from_iter_values(

Reply via email to