Skip to content

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

@donv

Description

@donv

@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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions