rust-geo-booleanop icon indicating copy to clipboard operation
rust-geo-booleanop copied to clipboard

Panic: index out of bounds

Open intendednull opened this issue 4 years ago • 3 comments

My app generates polygons many times a second. Sometimes it panics with the following:

index-c3cba34161ffd897.js:406 panicked at 'index out of bounds: the len is 1 but the index is 4294967295', /home/user/.cargo/git/checkouts/rust-geo-booleanop-3fbb75e5fa6cd1f8/188f016/lib/src/boolean/connect_edges.rs:180:38

It only seems to happen when taking the difference. Below are some vertices that have caused the issue:

p1 = [(-87.89134, 223.90228), (-93.1746, -213.39839), (-99.17416, -213.32591), (-93.8909,  223.97476)]
p2 = [(-30.8955, 223.21368), (-33.432434, 13.228989), (-153.42368, -14.678665), (-150.88675, 224.66336)]

intendednull avatar Aug 20 '21 23:08 intendednull

the index is 4294967295

In case you missed it, 4294967295 == 2**32 - 1, so, I'm suspicious of some kind of overflow.

Are you working with huge numbers of geometries?

Also I noticed from your error message:

index-c3cba34161ffd897.js:406

So, am I correct that you're targeting wasm?

Do you have any reproducible script that can induce this panic?

michaelkirk avatar Sep 30 '21 08:09 michaelkirk

I have also encountered this issue. It seems that the problem occurs when get_output_contour_id() returns -1 as this (i32) is then converted to a usize and causes this problem.

https://github.com/21re/rust-geo-booleanop/blob/7198a0321c3274de6f21aa5ee7456a4763151338/lib/src/boolean/connect_edges.rs#L176-L180

It seems that output_contour_id is initialised to -1 and so I guess this is never updated before it is accessed? Do you know why that would be?

AlanRace avatar May 27 '22 13:05 AlanRace

Just a guess, but I think it may all come down to the discussion over here: https://github.com/21re/rust-geo-booleanop/issues/17#issuecomment-610811690

Mutating the search tree in a way that violates the search tree invariant can sooner or later lead to a bug. I assume this is just another (later) manifestation of the problem.

bluenote10 avatar May 27 '22 15:05 bluenote10