Skip to content

Conversation

@jhawthorn
Copy link
Member

@jhawthorn jhawthorn commented Nov 8, 2024

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

As of #11238, certain regex we end up freeing stk_alloc AKA msa->stack_p twice, once in FREE_MATCH_ARG and once in the code here. This is very similar to a problem which was previously fixed by 6f6a2d2.

This one is a bit hard to reproduce. I'm still searching if there is a more reliable way to reproduce (either too short or too long a timeout and it doesn't seem to occur). I'll continue that tomorrow and then file a bug in the tracker for backport.

> Regexp.new('(?:xxx(?:s*[x]+)*+)|(?:^\s*(?:a|b|\s*)fxxx)', timeout: 0.2).match?("foo\n"*10 + (" " * 460 + "\n") * 10)
ruby(80654,0x1f357f840) malloc: double free for ptr 0x150008000
ruby(80654,0x1f357f840) malloc: *** set a breakpoint in malloc_error_break to debug
zsh: abort      irb

cc @composerinteralia @peterzhu2118

As of 1057485, it's possible to crash
on a double free due to `stk_alloc` AKA `msa->stack_p` being freed
twice, once at the end of match_at and a second time in `FREE_MATCH_ARG`
in the parent caller.

Fixes [Bug #20886]
@jhawthorn jhawthorn enabled auto-merge (rebase) November 12, 2024 07:07
@jhawthorn jhawthorn merged commit 8409edc into ruby:master Nov 12, 2024
68 checks passed
@mame
Copy link
Member

mame commented Nov 13, 2024

Thank you!

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

Successfully merging this pull request may close these issues.

2 participants