ishaaaan17 opened a new pull request, #55244:
URL: https://github.com/apache/arrow/pull/55244
### Rationale for this change
In `python/pyarrow/includes/libparquet.pxd` and
`python/pyarrow/_parquet.pxd`, Cython C++ method declarations for metadata
accessors (such as `ColumnChunkMetaData.statistics()`, `geo_statistics()`,
`crypto_metadata()`, `RowGroupMetaData.ColumnChunk()`,
`FileMetaData.RowGroup()`, `WriteTo()`, and `CFileMetaData_Make`) lacked
`except +` / `except *`.
When reading a Parquet file with corrupted or mismatched footer metadata
(e.g. repetition level mismatches or physical type mismatches between
SchemaElement and ColumnMetaData), C++ throws a `parquet::ParquetException`.
Because the Cython declaration lacked `except +`, Cython does not generate a
C++ `try ... catch (...)` wrapper. When the C++ exception crosses the C
boundary into Cython, it immediately triggers `std::terminate`, terminating the
Python interpreter with `SIGABRT` instead of raising a catchable Python
exception (`OSError`).
### What changes are included in this PR?
- Added `except +` to C++ declarations in
`python/pyarrow/includes/libparquet.pxd`:
- `statistics() const except +`
- `geo_statistics() const except +`
- `crypto_metadata() const except +`
- `ColumnChunk(int i) const except +`
- `RowGroup(int i) except +`
- `WriteTo(COutputStream* dst) const except +`
- `CFileMetaData_Make(...) except +`
- Added `except *` to inline init methods in `python/pyarrow/_parquet.pxd`:
- `RowGroupMetaData.init(...) except *:`
- `ColumnChunkMetaData.init(...) except *:`
- Added regression tests in `python/pyarrow/tests/parquet/test_metadata.py`
checking that damaged metadata (repetition type mismatch and physical type
mismatch) raises `OSError` rather than crashing the interpreter.
### Are these changes tested?
Yes, regression test added in
`python/pyarrow/tests/parquet/test_metadata.py`:
`test_damaged_metadata_raises_exception_not_abort(tmp_path)`.
### Are there any user-facing changes?
No public API changes. Damaged parquet metadata accessors will now cleanly
raise Python exceptions (`OSError`) instead of terminating the process.
**This PR contains a "Critical Fix".**
This PR fixes a bug that causes a crash (`std::terminate` / `SIGABRT`) when
metadata in a Parquet file footer is damaged or has type mismatches.
### Was AI used for this PR?
In accordance to the [AI generation
guidelines](https://arrow.apache.org/docs/dev/developers/overview.html#ai-generated-code),
please disclose below whether and how AI was used in this PR.
**PR code and description written by:**
- [x] Human
- [x] AI
**Reviewed before submission by:**
- [x] Human
- [ ] AI
- [ ] Not reviewed
I used an LLM assistant to trace the Cython declarations causing
`std::terminate` when `parquet::ParquetException` is thrown, and to help
structure the regression test cases. I verified the Cython exception
propagation behavior and validated the test cases and code changes.
* GitHub Issue: #54957
--
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]