ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-core:103127] [Ruby master Bug#17765] Segmentation fault when calling String#gsub
@ 2021-03-31 11:57 paul
  2021-03-31 13:10 ` [ruby-core:103128] " mame
  2021-03-31 22:13 ` [ruby-core:103134] " jean.boussier
  0 siblings, 2 replies; 3+ messages in thread
From: paul @ 2021-03-31 11:57 UTC (permalink / raw)
  To: ruby-core

Issue #17765 has been reported by lenwood (Paul Martensen).

----------------------------------------
Bug #17765: Segmentation fault when calling String#gsub
https://bugs.ruby-lang.org/issues/17765

* Author: lenwood (Paul Martensen)
* Status: Open
* Priority: Normal
* ruby -v: ruby 2.7.2p137 (2020-10-01 revision 5445e04352) [x86_64-linux-musl]
* Backport: 2.5: UNKNOWN, 2.6: UNKNOWN, 2.7: UNKNOWN, 3.0: UNKNOWN
----------------------------------------
We recently had a ruby segfault occuring while invoking `String#gsub`. 

The line in the code looks like this:

``` ruby
def sanitize_for_prometheus(string_or_symbol)
  reg = /[^a-zA-Z_0-9]/
  string_or_symbol.to_s.downcase.gsub(reg, '_')
end
```

And we've tried to replicate the segfault (on a different machine) with this script:

```rb
def sanitize_for_prometheus(string_or_symbol)
  reg = /[^a-zA-Z_0-9]/
  string_or_symbol.to_s.downcase.gsub(reg, '_')
end

def rand_string_or_symbol
  @o ||= [('a'..'z').to_a, ('A'..'Z').to_a, (0..9).to_a, '-', '.'].flatten
  str = @o.sample(50).join
  rand > 0.5 ? str.to_sym : str
end

loop { sanitize_for_prometheus rand_string_or_symbol }
```

But without success so far. I have attached a shortened version of the log file for reference.

 


---Files--------------------------------
segfault.log (60.8 KB)
segfault_gsub.rb (343 Bytes)


-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [ruby-core:103128] [Ruby master Bug#17765] Segmentation fault when calling String#gsub
  2021-03-31 11:57 [ruby-core:103127] [Ruby master Bug#17765] Segmentation fault when calling String#gsub paul
@ 2021-03-31 13:10 ` mame
  2021-03-31 22:13 ` [ruby-core:103134] " jean.boussier
  1 sibling, 0 replies; 3+ messages in thread
From: mame @ 2021-03-31 13:10 UTC (permalink / raw)
  To: ruby-core

Issue #17765 has been updated by mame (Yusuke Endoh).


It is difficult to identify the problem because the log lacks C level backtrace information maybe due to musl.

Are you using Alpine Linux? If so could you try Debian with glibc?

----------------------------------------
Bug #17765: Segmentation fault when calling String#gsub
https://bugs.ruby-lang.org/issues/17765#change-91202

* Author: lenwood (Paul Martensen)
* Status: Open
* Priority: Normal
* ruby -v: ruby 2.7.2p137 (2020-10-01 revision 5445e04352) [x86_64-linux-musl]
* Backport: 2.5: UNKNOWN, 2.6: UNKNOWN, 2.7: UNKNOWN, 3.0: UNKNOWN
----------------------------------------
We recently had a ruby segfault occuring while invoking `String#gsub`. 

The line in the code looks like this:

``` ruby
def sanitize_for_prometheus(string_or_symbol)
  reg = /[^a-zA-Z_0-9]/
  string_or_symbol.to_s.downcase.gsub(reg, '_')
end
```

And we've tried to replicate the segfault (on a different machine) with this script:

```rb
def sanitize_for_prometheus(string_or_symbol)
  reg = /[^a-zA-Z_0-9]/
  string_or_symbol.to_s.downcase.gsub(reg, '_')
end

def rand_string_or_symbol
  @o ||= [('a'..'z').to_a, ('A'..'Z').to_a, (0..9).to_a, '-', '.'].flatten
  str = @o.sample(50).join
  rand > 0.5 ? str.to_sym : str
end

loop { sanitize_for_prometheus rand_string_or_symbol }
```

But without success so far. I have attached a shortened version of the log file for reference.

 


---Files--------------------------------
segfault.log (60.8 KB)
segfault_gsub.rb (343 Bytes)


-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [ruby-core:103134] [Ruby master Bug#17765] Segmentation fault when calling String#gsub
  2021-03-31 11:57 [ruby-core:103127] [Ruby master Bug#17765] Segmentation fault when calling String#gsub paul
  2021-03-31 13:10 ` [ruby-core:103128] " mame
@ 2021-03-31 22:13 ` jean.boussier
  1 sibling, 0 replies; 3+ messages in thread
From: jean.boussier @ 2021-03-31 22:13 UTC (permalink / raw)
  To: ruby-core

Issue #17765 has been updated by byroot (Jean Boussier).


> But without success so far.

I wouldn't be surprised if the bug wasn't in `gsub` itself, but in some C extension that would generate a faulty string on which `gsub` would trip. I see you have `thrift` loaded for instance. IIRC that's a binary format parser like protobuf etc, it might be creating strings improperly.

This could prove very hard to track. 

----------------------------------------
Bug #17765: Segmentation fault when calling String#gsub
https://bugs.ruby-lang.org/issues/17765#change-91207

* Author: lenwood (Paul Martensen)
* Status: Open
* Priority: Normal
* ruby -v: ruby 2.7.2p137 (2020-10-01 revision 5445e04352) [x86_64-linux-musl]
* Backport: 2.5: UNKNOWN, 2.6: UNKNOWN, 2.7: UNKNOWN, 3.0: UNKNOWN
----------------------------------------
We recently had a ruby segfault occuring while invoking `String#gsub`. 

The line in the code looks like this:

``` ruby
def sanitize_for_prometheus(string_or_symbol)
  reg = /[^a-zA-Z_0-9]/
  string_or_symbol.to_s.downcase.gsub(reg, '_')
end
```

And we've tried to replicate the segfault (on a different machine) with this script:

```rb
def sanitize_for_prometheus(string_or_symbol)
  reg = /[^a-zA-Z_0-9]/
  string_or_symbol.to_s.downcase.gsub(reg, '_')
end

def rand_string_or_symbol
  @o ||= [('a'..'z').to_a, ('A'..'Z').to_a, (0..9).to_a, '-', '.'].flatten
  str = @o.sample(50).join
  rand > 0.5 ? str.to_sym : str
end

loop { sanitize_for_prometheus rand_string_or_symbol }
```

But without success so far. I have attached a shortened version of the log file for reference.

 


---Files--------------------------------
segfault.log (60.8 KB)
segfault_gsub.rb (343 Bytes)


-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-03-31 22:13 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-31 11:57 [ruby-core:103127] [Ruby master Bug#17765] Segmentation fault when calling String#gsub paul
2021-03-31 13:10 ` [ruby-core:103128] " mame
2021-03-31 22:13 ` [ruby-core:103134] " jean.boussier

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).