Pyo3: SIGSEGV when PyIterator is given an integer

Created on 26 May 2019  路  1Comment  路  Source: PyO3/pyo3

馃悰 Bug Reports

PyIterator creates a SIGSEGV when passed an integer.

馃實 Environment

  • Your operating system and version: Arch Linux 5.1.4-arch1-1-ARCH
  • Your python version: 3.7.3
  • How did you install python (e.g. apt or pyenv)? Did you use a virtualenv?: pacman -S python
  • Your rust version (rustc --version): rustc 1.36.0-nightly (7158ed9cb 2019-05-15)
  • Are you using the latest pyo3 version? Have you tried using latest master (replace version = "0.x.y" with git = "https://github.com/PyO3/pyo3")? yes, yes

馃挜 Reproducing

The following program will panic:

extern crate pyo3;

use pyo3::prelude::*;
use pyo3::types::PyIterator;

fn main() {
    let gil = Python::acquire_gil();
    let py = gil.python();

    let obj = 1.into_object(py);
    assert!(PyIterator::from_object(py, &obj).is_err());
}

with Cargo.toml:

[dependencies]
pyo3 = { git = "https://github.com/PyO3/pyo3" }
Unsound bug

Most helpful comment

This is because the return value from PyObject_GetIter in https://github.com/PyO3/pyo3/blob/master/src/types/iterator.rs#L42 is not checked for NULL.

I also don't understand why there is an additional PyIter_Check below (referring to #71)...

>All comments

This is because the return value from PyObject_GetIter in https://github.com/PyO3/pyo3/blob/master/src/types/iterator.rs#L42 is not checked for NULL.

I also don't understand why there is an additional PyIter_Check below (referring to #71)...

Was this page helpful?
0 / 5 - 0 ratings