ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-core:118686] [Ruby master Bug#20653] Memory leak in String#start_with? when regexp times out
@ 2024-07-25 19:34 peterzhu2118 (Peter Zhu) via ruby-core
  2024-07-26 13:43 ` [ruby-core:118696] " peterzhu2118 (Peter Zhu) via ruby-core
  2024-09-02  9:40 ` [ruby-core:119003] " k0kubun (Takashi Kokubun) via ruby-core
  0 siblings, 2 replies; 3+ messages in thread
From: peterzhu2118 (Peter Zhu) via ruby-core @ 2024-07-25 19:34 UTC (permalink / raw)
  To: ruby-core; +Cc: peterzhu2118 (Peter Zhu)

Issue #20653 has been reported by peterzhu2118 (Peter Zhu).

----------------------------------------
Bug #20653: Memory leak in String#start_with? when regexp times out
https://bugs.ruby-lang.org/issues/20653

* Author: peterzhu2118 (Peter Zhu)
* Status: Open
* Backport: 3.1: UNKNOWN, 3.2: WONTFIX, 3.3: REQUIRED
----------------------------------------
GitHub PR: https://github.com/ruby/ruby/pull/11247

This commit refactors how Onigmo handles timeout. Instead of raising a timeout error, onig_search will return a ONIGERR_TIMEOUT which the caller can free memory, and then raise a timeout error.

This fixes a memory leak in String#start_with when the regexp times out. For example:

```ruby
regex = Regexp.new("^#{"(a*)" * 10_000}x$", timeout: 0.000001)
str = "a" * 1000000 + "x"

10.times do
  100.times do
    str.start_with?(regex)
  rescue
  end

  puts `ps -o rss= -p #{$$}`
end
```

Before:

```
33216
51936
71152
81728
97152
103248
120384
133392
133520
133616
```

After:

```
14912
15376
15824
15824
16128
16128
16144
16144
16160
16160
```



-- 
https://bugs.ruby-lang.org/
 ______________________________________________
 ruby-core mailing list -- ruby-core@ml.ruby-lang.org
 To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
 ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/

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

* [ruby-core:118696] [Ruby master Bug#20653] Memory leak in String#start_with? when regexp times out
  2024-07-25 19:34 [ruby-core:118686] [Ruby master Bug#20653] Memory leak in String#start_with? when regexp times out peterzhu2118 (Peter Zhu) via ruby-core
@ 2024-07-26 13:43 ` peterzhu2118 (Peter Zhu) via ruby-core
  2024-09-02  9:40 ` [ruby-core:119003] " k0kubun (Takashi Kokubun) via ruby-core
  1 sibling, 0 replies; 3+ messages in thread
From: peterzhu2118 (Peter Zhu) via ruby-core @ 2024-07-26 13:43 UTC (permalink / raw)
  To: ruby-core; +Cc: peterzhu2118 (Peter Zhu)

Issue #20653 has been updated by peterzhu2118 (Peter Zhu).


Ruby 3.3 backport PR: https://github.com/ruby/ruby/pull/11255

----------------------------------------
Bug #20653: Memory leak in String#start_with? when regexp times out
https://bugs.ruby-lang.org/issues/20653#change-109233

* Author: peterzhu2118 (Peter Zhu)
* Status: Closed
* Backport: 3.1: UNKNOWN, 3.2: WONTFIX, 3.3: REQUIRED
----------------------------------------
GitHub PR: https://github.com/ruby/ruby/pull/11247

This commit refactors how Onigmo handles timeout. Instead of raising a timeout error, onig_search will return a ONIGERR_TIMEOUT which the caller can free memory, and then raise a timeout error.

This fixes a memory leak in String#start_with when the regexp times out. For example:

```ruby
regex = Regexp.new("^#{"(a*)" * 10_000}x$", timeout: 0.000001)
str = "a" * 1000000 + "x"

10.times do
  100.times do
    str.start_with?(regex)
  rescue
  end

  puts `ps -o rss= -p #{$$}`
end
```

Before:

```
33216
51936
71152
81728
97152
103248
120384
133392
133520
133616
```

After:

```
14912
15376
15824
15824
16128
16128
16144
16144
16160
16160
```



-- 
https://bugs.ruby-lang.org/
 ______________________________________________
 ruby-core mailing list -- ruby-core@ml.ruby-lang.org
 To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
 ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/

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

* [ruby-core:119003] [Ruby master Bug#20653] Memory leak in String#start_with? when regexp times out
  2024-07-25 19:34 [ruby-core:118686] [Ruby master Bug#20653] Memory leak in String#start_with? when regexp times out peterzhu2118 (Peter Zhu) via ruby-core
  2024-07-26 13:43 ` [ruby-core:118696] " peterzhu2118 (Peter Zhu) via ruby-core
@ 2024-09-02  9:40 ` k0kubun (Takashi Kokubun) via ruby-core
  1 sibling, 0 replies; 3+ messages in thread
From: k0kubun (Takashi Kokubun) via ruby-core @ 2024-09-02  9:40 UTC (permalink / raw)
  To: ruby-core; +Cc: k0kubun (Takashi Kokubun)

Issue #20653 has been updated by k0kubun (Takashi Kokubun).

Backport changed from 3.1: UNKNOWN, 3.2: WONTFIX, 3.3: REQUIRED to 3.1: UNKNOWN, 3.2: WONTFIX, 3.3: DONE

ruby_3_3 commit:ce565cd4b851977bf37a470bee54e441bb60486d.

----------------------------------------
Bug #20653: Memory leak in String#start_with? when regexp times out
https://bugs.ruby-lang.org/issues/20653#change-109578

* Author: peterzhu2118 (Peter Zhu)
* Status: Closed
* Backport: 3.1: UNKNOWN, 3.2: WONTFIX, 3.3: DONE
----------------------------------------
GitHub PR: https://github.com/ruby/ruby/pull/11247

This commit refactors how Onigmo handles timeout. Instead of raising a timeout error, onig_search will return a ONIGERR_TIMEOUT which the caller can free memory, and then raise a timeout error.

This fixes a memory leak in String#start_with when the regexp times out. For example:

```ruby
regex = Regexp.new("^#{"(a*)" * 10_000}x$", timeout: 0.000001)
str = "a" * 1000000 + "x"

10.times do
  100.times do
    str.start_with?(regex)
  rescue
  end

  puts `ps -o rss= -p #{$$}`
end
```

Before:

```
33216
51936
71152
81728
97152
103248
120384
133392
133520
133616
```

After:

```
14912
15376
15824
15824
16128
16128
16144
16144
16160
16160
```



-- 
https://bugs.ruby-lang.org/
 ______________________________________________
 ruby-core mailing list -- ruby-core@ml.ruby-lang.org
 To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
 ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/

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

end of thread, other threads:[~2024-09-02  9:40 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-07-25 19:34 [ruby-core:118686] [Ruby master Bug#20653] Memory leak in String#start_with? when regexp times out peterzhu2118 (Peter Zhu) via ruby-core
2024-07-26 13:43 ` [ruby-core:118696] " peterzhu2118 (Peter Zhu) via ruby-core
2024-09-02  9:40 ` [ruby-core:119003] " k0kubun (Takashi Kokubun) via ruby-core

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 NNTP newsgroup(s).