Michael-F-Bryan / rust-ffi-guide

A guide for doing FFI using Rust
https://michael-f-bryan.github.io/rust-ffi-guide/
Creative Commons Zero v1.0 Universal
282 stars 18 forks source link

Sieve crashes in pythonic section #32

Closed gurgalex closed 7 years ago

gurgalex commented 7 years ago

I don't know if this is a bug, but here are some test cases that do and don't produce Index out of Bound Crashes

    with Sieve(7) as s:
        print(s.is_prime(11))

Upper bound reports that the largest number known about is 10

limit=8 does not crash

    with Sieve(8) as s:
        print(s.is_prime(11)) # true

Upper bound returns 12

So, it will crash if the number being checked is greater than the upper bound. The primal docs seem to say that it will sieve out all primes up to limit. What is limit?

gurgalex commented 7 years ago

It will be at least as large as the number passed to new, but may be slightly larger.

I guess the only issue is that crash info and core dumps are exposed to Python.

Michael-F-Bryan commented 7 years ago

Well that's interesting. I guess we need to add a check in Sieve.is_prime() which checks the number being queried is lower than the limit and throws an exception if that's not the case.

gurgalex commented 7 years ago

The primal documentation explains the crash If n is out of range (greater than self.upper_bound()), is_prime will panic.