GHSA-7whj-cfh7-xgm4 is a heap-based out-of-bounds write (CWE-787) in Ruby's Regexp#to_s. The advisory and the ruby-lang news page credit Stephan Lipp (Ada Logics) and Anthropic, and the upstream fix (ruby/ruby commit 12da5c28 on master, backported as cdd499ec for 3.4 and ee06abac for 4.0) carries exactly that credit and is titled "Preprocess the source before Regexp#to_s checks it with Onigmo". That commit only touches re.c and adds the regression test test_to_s_comment_in_char_class with Regexp.new('(?:[](?#\\x{7FFFFFFF})])').
Root cause: Regexp#to_s is implemented by rb_reg_to_s() -> rb_reg_str_with_term(). When the pattern source starts with a group of the form (?opts:...), rb_reg_str_with_term() attempts to prove the wrapper is redundant by re-compiling the inner source standalone with Onigmo's onig_new(). In the vulnerable code that re-compilation is fed the RAW source bytes. Regexp.new(), by contrast, always compiles the PREPROCESSED source (rb_reg_preprocess() unescapes/normalizes the pattern). The two therefore disagree on what the pattern means whenever a construct such as (?#...) occurs inside a character class - the raw text is a different (attacker-shaped) pattern than the one the regexp was built from. Compiling that divergent pattern inside onig_new() reaches an Onigmo code-point escape path (\\x{7FFFFFFF}) that writes past the end of a heap buffer, giving the information disclosure / RCE described in the advisory.
The patch fixes the flaw by calling rb_reg_preprocess() on the substring before onig_new(), so Onigmo sees the same preprocessed pattern that Regexp.new() used. The vulnerable function is rb_reg_str_with_term() (the function that was modified and that lacked the preprocessing), with rb_reg_to_s() (the Regexp#to_s method entry that delegates to it) also present on the runtime stack when the bug fires. rb_reg_preprocess() itself is the mitigation introduced by the patch and is not a vulnerable function.