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

Fatal signal 7 when handling a UTF-8 string with Norwegian characters on Samsung Galaxy Tab A #10

Open
donv opened this issue Oct 3, 2019 · 1 comment

Comments

@donv
Copy link
Member

donv commented Oct 3, 2019

@headius I have spent weeks on this one :)

This is a patch we used for JRuby 1.7.13 as well, so it is not new, just expanded in scope, somehow.

%i[\[\] bytes inspect length size to_s].each do |method_name|
    class_eval <<~METHOD_DEFINITION
      def #{method_name}(*args, &block)
        return super if ascii_only?
        return dup.#{method_name}(*args, &block) if frozen?
        original_encoding = encoding
        force_encoding(Encoding::BINARY).force_encoding(original_encoding)
        super
      end
    METHOD_DEFINITION
  end

We have a test that uncovers the bug:

  utf8 = 'ÆøåæØåœøÅ'
  puts "utf8: [0]: #{utf8[0]}"
  puts "utf8: [0, 15]: #{utf8[0, 15]}"
  puts "utf8: [0..12]: #{utf8[0..12]}"
  puts "utf8: [0..16]: #{utf8[0..16]}"
  puts "utf8: [0..80]: #{utf8[0..80]}"
  puts "utf8: [0..4096]: #{utf8[0..4096]}"
  puts "utf8[0..4096]: #{utf8[0..4096]}"
  puts "utf8: bytes: #{utf8.bytes}"
  puts "utf8: bytes: to_a: size: #{utf8.bytes.to_a.size}"

It will cause a Fatal signal 7 on "Samsung Galaxy Tab A" tablets even across Android versions 7, 8.0, and 8.1.

This patch solves most of our use cases, but one is still failing, and I am working on trying to find if more methods need to be patched.

@headius I do not understand why the patch works. Maybe you have an idea?

@donv
Copy link
Member Author

donv commented Oct 3, 2019

I just found that the bug is now occurring when passing a Ruby UTF-8 string of more than 16 bytes with non-ascii characters to a Java method (in our case https://developer.android.com/reference/android/app/Activity.html#setTitle(java.lang.CharSequence)).

Converting the argument using #to_java_string works.

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
@donv and others