meet987654 opened a new pull request, #12490:
URL: https://github.com/apache/arrow-rs/pull/12490

   # Which issue does this PR close?
   
   - Closes #12472
   
   # Rationale for this change
   
   A parquet footer can describe a schema that nests arbitrarily deep. Nothing 
bounds that depth, and the schema is converted and later walked recursively, so 
a small crafted footer (about 19 KB, about 2,430 nested groups) overflows the 
stack and aborts the process from `ParquetMetaDataReader::decode_metadata` 
instead of returning an error. Details of the reproduction are in the issue.
   
   # What changes are included in this PR?
   
   - `schema_from_array_helper` (`parquet/src/schema/types.rs`) now tracks the 
nesting depth. It returns a `ParquetError` once the schema nests deeper than 
`MAX_SCHEMA_DEPTH` (128) levels.
   - Because the check runs while the footer is decoded, every later recursive 
walk of the schema (for example, building the arrow schema and the array 
readers) only ever sees a bounded depth. This follows the same approach as 
#12142, which bounded `num_children`.
   
   128 is far beyond what real-world schemas use. The embedded `ARROW:schema` 
already fails at around 64 levels with the default flatbuffers depth limit (see 
#12485).
   
   # Are these changes tested?
   
   Yes, three new unit tests in `parquet/src/schema/types.rs`:
   - a schema at exactly the limit is accepted
   - a schema one level past the limit is rejected with an error
   - a 100,000-level schema decoded on a 2 MiB thread returns `Err` instead of 
overflowing the stack
   
   # Are there any significant user-facing changes?
   
   Files whose schema nests deeper than 128 levels can no longer be read. They 
now return an error instead of overflowing the stack. Note that `ArrowWriter` 
can still write such files (with `skip_arrow_metadata`), so a writer-side check 
could be a follow-up if that's wanted.
   
   # AI usage disclosure
   
   I used an AI assistant (Claude) to help reproduce the overflow, draft the 
depth check and tests, and write this description. I reviewed and tested all 
the changes myself.
   


-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to