Skip to content
Memory corruption Disclosed report Advanced

Invalid read in `str_replace_partial`

A memory-safety bug in mruby's string replacement routine causes an out-of-bounds read when a crafted script triggers the affected code path. The reporter states this could potentially lead to information disclosure.

dgaletic Follow

Originally disclosed on HackerOne

Bounty$1,000 View original
  • Triaged in 32 hours
  • Fixed in 3 days
  • Paid in 3 days
  • Disclosed after 2 months

PoC

The attached POC shows an invalid read.

Debug info

The issue happens when memmove is called inside str_replace_partial.

valgrind report:

0==27051== Invalid read of size 1
==27051==    at 0x483FA10: memmove (vg_replace_strmem.c:1270)
==27051==    by 0x135D60: str_replace_partial (string.c:1193)
==27051==    by 0x1359CB: mrb_str_aset (string.c:1226)
==27051==    by 0x131AE8: mrb_str_aset_m (string.c:1255)
==27051==    by 0x1656FE: mrb_f_send (vm.c:633)
==27051==    by 0x169C3E: mrb_vm_exec (vm.c:1441)
==27051==    by 0x166540: mrb_vm_run (vm.c:949)
==27051==    by 0x17A5C7: mrb_top_run (vm.c:2837)
==27051==    by 0x153113: mrb_load_exec (parse.y:6318)
==27051==    by 0x1533E6: mrb_load_file_cxt (parse.y:6327)
==27051==    by 0x10DC3C: main (mruby.c:270)
==27051==  Address 0x4da9370 is 176 bytes inside an unallocated block of size 2,796,832 in arena "client"

git bisect shows the issue was introduced in 0d452073.

Test platform

  • Arch Linux

Thank you, Dinko Galetic Denis Kasak

Impact

Potential information disclosure.

The original report as published on HackerOne, by dgaletic. Images and videos are our own copies; raw HTML is shown as text. View it on HackerOne.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

How it worked

Root cause

Likely an incorrect length or offset calculation in the partial string replacement logic, so the memory move reads beyond the allocated buffer.

Impact

The reporter says the flaw could potentially lead to information disclosure, though no concrete leak is demonstrated.

What the attacker needed

Running a crafted mruby script

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

A program that runs Ruby-like scripts (mruby) has a function that edits text in place. Under certain inputs it reads one byte past the memory it was given, which is a memory-safety mistake that can leak data or crash the program.

What is Memory corruption?

Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.

More by dgaletic

View all

13 more disclosed reports, best first.

More from shopify-scripts

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Memory corruption

The lesson behind this report.

Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.