Skip to content
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

Segmentation fault on non-strings #1

Open
bbugh opened this issue Apr 25, 2018 · 6 comments
Open

Segmentation fault on non-strings #1

bbugh opened this issue Apr 25, 2018 · 6 comments

Comments

@bbugh
Copy link

bbugh commented Apr 25, 2018

Thanks for this gem, it's much faster than any of the other ones.

We've run into an issue that is easy to work around but I thought it worth reporting so it can have a better check than a segfault.

Issue: Passing an array of non-strings creates a segfault.

Expectation: Error message, exception, or automatic conversion to string.

Actual: the Ruby interpreter dies, taking the whole server down with it.

Reproduce:

Unnatural.sort([1, 2, 3])
# => segfault

Unnatural.sort([1..5, 8..6])
# => segfault

Unnatural.sort([:one, :two])
# => segfault

# ironically does not segfault:
Unnatural.sort([Object.new, Object.new])
=> [#<Object:0x007fdee21af130>, #<Object:0x007fdee21af108>]

We can, of course, use to_s with sort_by but I don't think it should break everything with the wrong type. 😄

@bjmllr
Copy link
Owner

bjmllr commented Apr 25, 2018

What version of the gem are you using? I can reproduce the segfault on 0.2.0, but on 0.3.1 I get a TypeError:

pry> Unnatural::Fast.sort([1, 2, 3])
TypeError: no implicit conversion of Fixnum into String

@bbugh
Copy link
Author

bbugh commented Apr 25, 2018

Hi there!

I have whatever version is installed by gem 'unnatural', just added it today.

Gemfile.lock says it's 0.2.0:

    unnatural (0.2.0)

@bjmllr
Copy link
Owner

bjmllr commented Apr 25, 2018

Strange, 0.3.1 was pushed to rubygems.org before today so you should have gotten that version. If you didn't give a specific version in Gemfile, maybe try bundle update unnatural? Or see if gem install unnatural -v0.3.1 gives an error?

@bbugh
Copy link
Author

bbugh commented Apr 25, 2018

Good thought, manually installing with gem install unnatural -v0.3.1 worked fine.

I then completely deleted all traces of unnatural from my system and Gemfile, re-ran bundler, added unnatural back to my Gemfile and ran bundler again, and it still installed 0.2.0. This is with ruby 2.2.4p230 (2015-12-16 revision 53155) [x86_64-darwin16].

I went to a non-rvm locked directory and made a new Gemfile, and it installed 0.3.1. That's with ruby 2.5.0p0 (2017-12-25 revision 61468) [x86_64-darwin16].

Maybe it's a dependency thing.

@bbugh
Copy link
Author

bbugh commented Apr 25, 2018

Further investigation, I added gem 'unnatural', '~> 0.3.1' and that showed the problem. The package gemspec is locking to a particular rake version, which seems like it should be a dev dependency and not a package dependency.

Fetching gem metadata from https://rubygems.org/............
Fetching gem metadata from https://rubygems.org/.
Resolving dependencies....
Bundler could not find compatible versions for gem "rake":
  In snapshot (Gemfile.lock):
    rake (= 12.0.0)

  In Gemfile:
    ... 

    unnatural (~> 0.3.1) was resolved to 0.3.1, which depends on
      rake (< 12, >= 9)

Running `bundle update` will rebuild your snapshot from scratch, using only
the gems in your Gemfile, which may resolve the conflict.

This seems to be the culprit: https://github.com/bjmllr/unnatural/blob/669c8e9/unnatural.gemspec#L26

@bjmllr
Copy link
Owner

bjmllr commented Apr 27, 2018

I have removed that line and released a new version (0.3.2). Does this fix the problem for you? rake is still a runtime dependency since ffi-compiler uses it, but there should be no version restriction any more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants