-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
sort segfaults #681
Comments
Linux, 64-bit, libc 2.13. recent trunk build Segfault happens, backtrace useless #0 0x00007fffee3533ef in ?? () |
It appears to be an infinite recursion. quicksort appears to recurse infinitely (or break in one of several other ways) if given a sufficiently large chunk of identical values at any point during the computation (over the threshold for using an insertionsort). ie, try zz=[.1,.1,.1,.1,.1,.1,.1,.1,.1,.1,.1,.1,.1,.1,.1,.1,.1,.1,.1,.1,.1,.1] |
@ViralBShah: can you take a look at this? The quicksort code was originally yours. I will also take a look. |
Bisecting on Linux / 64-bit / glibc-2.13:
|
I think that the root cause are the line
(sort.jl : 77) and the fact
So, while quicksort code relies on the fact that some element of array is no less than pivot, this assumption can be false. I can understand a few ways to fix it in a straightforward way (for example, taking 4 sample points could help, because there is no rounding off in division by 4) that doesn't hurt basic asimptotical beaviour, but I am not sure what is the best fix to keep constants in complexity small. |
Interesting. That's an excellent find. I didn't get around to investigating this yet, so that's very much appreciated. We can change the pivot selection for now and convert a segfault into correct behavior with a potential performance problem on some array orderings. |
This increases possibility of quadratic-time exploit, I guess |
Yeah — as noted in my commit message. But I'd rather have a potential performance regression than a segfault. |
f2a067a forgot that step.
All commits from master applied to my fork (which doesn't touch sort.jl),
make clean
,make test
passes, I get the following. Other arrays work; this one doesn't:The text was updated successfully, but these errors were encountered: