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

alamb 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 84b3454be5 fix: ParquetError when reading corrupt parquet file with 
truncated data instead of Panic (#9725)
84b3454be5 is described below

commit 84b3454be50ac8697d2bad4d9a57d549b78e8c6e
Author: xuzifu666 <[email protected]>
AuthorDate: Fri Apr 17 00:12:05 2026 +0800

    fix: ParquetError when reading corrupt parquet file with truncated data 
instead of Panic (#9725)
    
    # Which issue does this PR close?
    
    <!--
    We generally require a GitHub issue to be filed for all bug fixes and
    enhancements and this helps us generate change logs for our releases.
    You can link an issue to this PR using the GitHub syntax.
    -->
    
    - Closes https://github.com/apache/arrow-rs/issues/9705
    
    # Rationale for this change
    
    <!--
    Why are you proposing this change? If this is already explained clearly
    in the issue then this section is not needed.
    Explaining clearly why changes are proposed helps reviewers understand
    your changes and offer better suggestions for fixes.
    -->
    
    # What changes are included in this PR?
    
    <!--
    There is no need to duplicate the description in the issue here but it
    is sometimes worth providing a summary of the individual changes in this
    PR.
    -->
    
    # Are these changes tested?
    
    <!--
    We typically require tests for all PRs in order to:
    1. Prevent the code from being accidentally broken by subsequent changes
    2. Serve as another way to document the expected behavior of the code
    
    If tests are not included in your PR, please explain why (for example,
    are they covered by existing tests)?
    -->
    
    # Are there any user-facing changes?
    
    <!--
    If there are user-facing changes then we may require documentation to be
    updated before approving the PR.
    
    If there are any breaking changes to public APIs, please call them out.
    -->
---
 parquet/src/file/metadata/reader.rs | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/parquet/src/file/metadata/reader.rs 
b/parquet/src/file/metadata/reader.rs
index 2be9dcbd4b..60c57129fd 100644
--- a/parquet/src/file/metadata/reader.rs
+++ b/parquet/src/file/metadata/reader.rs
@@ -530,7 +530,13 @@ impl ParquetMetaDataReader {
                 let remainder_start = *remainder_start as u64;
                 let offset = usize::try_from(range.start - remainder_start)?;
                 let end = usize::try_from(range.end - remainder_start)?;
-                assert!(end <= remainder.len());
+                if end > remainder.len() {
+                    return Err(general_err!(
+                        "Corrupted parquet file: index data range ({:?}) 
exceeds remainder length ({})",
+                        range,
+                        remainder.len()
+                    ));
+                }
                 remainder.slice(offset..end)
             }
             // Note: this will potentially fetch data already in remainder, 
this keeps things simple
@@ -538,7 +544,13 @@ impl ParquetMetaDataReader {
         };
 
         // Sanity check
-        assert_eq!(bytes.len() as u64, range.end - range.start);
+        if bytes.len() as u64 != range.end - range.start {
+            return Err(general_err!(
+                "Corrupted parquet file: index data length mismatch, expected 
{}, got {}",
+                range.end - range.start,
+                bytes.len()
+            ));
+        }
         push_decoder.push_range(range.clone(), bytes)?;
         let metadata = parse_index_data(&mut push_decoder)?;
         self.metadata = Some(metadata);

Reply via email to