waterWang opened a new pull request, #51020:
URL: https://github.com/apache/arrow/pull/51020
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
* Closes: #51019
### Rationale for this change
`KeyValueMetadata.key(i)` / `.value(i)` pass the index through to the C++
`KeyValueMetadata::key/value` accessors, whose `DCHECK` bounds checks are
compiled out in release builds. Any out-of-range or negative index — most
easily hit with `pa.KeyValueMetadata().key(0)` on an empty object — performs
an unchecked `std::vector::operator[]` access and **segfaults the Python
process** instead of raising an exception. Reproduced locally on pyarrow
25.0.1.
### What changes are included in this PR?
Bounds checks in the Python bindings (`types.pxi`) raise `IndexError` for
negative or out-of-range indexes, matching the behavior of other indexed
pyarrow containers.
### Are these changes tested?
Yes — added `test_key_value_metadata_index_errors` covering in-bounds
access, out-of-range/negative indexes, and empty-metadata access. The
segfault reproduces on pyarrow 25.0.1 (SIGSEGV); with the fix the same
calls raise `IndexError`.
* Closes: #51019
--
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]