Repository navigation
fix: carry mruby's method_missing splat-keyword fix (550d10a) on the pinned VM - #81
Merged
Merged
Conversation
mruby 449627d's prepare_missing() copies the keyword Hash from argv[ci->n]. For a call that splats positional arguments ci->n is CALL_MAXARGS and the Hash is already in argv[1], so it reads argv[15], past the frame. Any `name(*args, **opts)`, `name(*args, k: 1)` or `name(...)` call to an undefined method reaches method_missing with garbage keywords: they are dropped, or a TypeError/NoMethodError about stack contents is raised. Upstream fixed this in 550d10a (mruby/mruby#6598, issue #6584). Moving the pin to a tree with it would also bring 9aaa7ce5fb and 7b59b50c87, which change VM behaviour, so the pin stays and the upstream commit is carried as a patch instead. Every build config applies it as minirake loads the config, which covers both artifact scripts and rake run by hand; the Android CMake build reads the tree host_vm has patched.
This was referenced Nov 16, 2026
AdamMusa
added a commit
that referenced
this pull request
Nov 17, 2026
kernel_helper_shadowing_test gains test_ruflet_and_ruflet_ui_build_what_ruflet_dsl_builds. The 63 ScopedControlForwarders methods are now reached only through Ruflet.* and Ruflet::UI.*, and before this only respond_to? and a few names pinned them. The test compares Ruflet.<name> and Ruflet::UI.<name> with Ruflet::DSL.<name> for every scoped name over four shapes: keywords only, an empty positional, a control positional, and a block that adds a child. It adds the keywords a helper needs to build (body: for nested_scroll_view, title: for stepper_step). It also checks that each built patch shows key:, the positional control and the block's child, so a dropped keyword, argument or block changes what is compared. scoped_helper_test.rb now describes the mruby 449627d limit correctly. A splat-forwarded call to a missing method can build without its keywords, build with an earlier call's keywords, or raise. It names the fix, upstream 550d10adb7, which #81 carries as a VM build patch. The probe now runs all three forms the gated checks use: `*a, **k`, `*a` plus a literal keyword, and `...`. It runs them after a call that leaves other keywords behind, and compares positional arguments and keywords exactly. A VM built with the patch runs every check. A new gated check covers the stale case: carouselview forwarded right after a call with key: "earlier" must build with its own key: "k". No lib change.
This was referenced Nov 17, 2026
git_apply now raises 'git is required to apply ruby_runtime/vm/patches' when system cannot run git, instead of reporting the patch as misfitting. build_vm_artifacts.sh lists git in the container image it documents. The tests load every build config against stand-ins for MRuby and RufletMrubyPatches, so a commented-out or unreachable hook fails, and they pin the patch's changed lines to upstream 550d10a.
build-ruflet-client.yml runs tools/mruby_patches_test.rb next to the framework tests, and a pull request that changes only that test runs it.
AdamMusa
marked this pull request as ready for review
November 20, 2026 05:44
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The bug
In mruby
449627d(theruby_runtime/third_party/mrubygitlink),prepare_missing()insrc/vm.crunsWhen a call splats positional arguments,
ci->n == CALL_MAXARGS(15) and the keyword Hash is already inargv[1]. The line then readsargv[15], past the frame. So a call to an undefined method written asname(*args, **opts),name(*args, k: 1),name(...), or with 15+ literal arguments and keywords, reachesmethod_missingwith the wrong keywords: none, an earlier call's, or whatever was on the stack.In Ruflet this hits v0.0.23 names reached through
Kernel#method_missing(e.g.def eb(*a, **k) = elevatedbutton(*a, **k)), and the scoped helpers from #67 (stepper,table,form, ...) whenever a wrapper forwards to them with a splat.Upstream: mruby/mruby#6584, fixed by mruby/mruby#6598 (commit
550d10adb76a1bde1954ea78e1b8b5451c74cec3, merged as72c9e5don 2026-03-09):Why a patch and not a pin bump
The smallest pin move that contains the fix is
72c9e5d, and it is not a one-hunk change.git diff --stat 449627d 72c9e5dis 18 files, 1995 insertions and 223 deletions. Besides docs, CI files and AUTHORS, it includes the mruby 4.0.0 version bump (include/mruby/version.h:MRUBY_RUBY_VERSION"3.4" to "4.0"),tasks/presym.rake,include/mruby/error.hand othersrc/vm.cchanges. Any later pin would also bring9aaa7ce5fb(2026-07-28, drops the visibility check on themethod_missingfallback) and7b59b50c87(2026-11-08,sendpasses keywords tomethod_missing). Each of those is a VM change to verify on its own. The fix needs one hunk.A fork commit was also an option. I did not take it: the fork would have to be fetchable by everyone who populates
third_party/mruby(there is no.gitmodules), everybuild_config/*.rb.lockwould change, and the fix would show in review as an opaque SHA. With a patch, the gitlink and the lock files stay as they are.What changes
ruby_runtime/vm/patches/mruby/0001-Fixed-heap-buffer-overflow-in-method_missing.patchis upstream550d10a(author dearblue), cherry-picked onto449627dwith-x. It applies to449627dwith no offset or fuzz.ruby_runtime/vm/patches/mruby_patches.rbapplies it withgit apply. It skips a patch the tree already has, and it raises when a patch neither applies nor is already there.GIT_CEILING_DIRECTORIESstops git from patching an enclosing checkout instead. When git cannot be run, it raisesgit is required to apply ruby_runtime/vm/patches, but it could not be run. Install git and put it on PATH.It also runs as a CLI:ruby ruby_runtime/vm/patches/mruby_patches.rb [--check] [MRUBY_DIR](exit 0 applied, 1 pending with--check, 2 on error).ruby_runtime/vm/build_config/*.rbbegins withrequire_relative "../patches/mruby_patches"andRufletMrubyPatches.apply(MRUBY_ROOT). minirake loads the config before it computes tasks, so the tree is patched before anything compiles. The Linux and Windowswith_host_buildwrappersloadthe config, and Android'sbuild_host_vmruns minirake withhost_vm.rbbefore CMake compilesthird_party/mruby/src.tools/build_vm_artifacts.sh: the documented container IMAGE lists git.tools/mruby_patches_test.rb(8 tests): loads every build config against stand-ins forMRubyandRufletMrubyPatchesand asserts thatapply(MRUBY_ROOT)runs before the build is declared; checks that the patch's changed lines are exactly upstream's; and covers idempotence, a misfit tree, a missing git (in-process and through the CLI), the enclosing-checkout guard, and the pinned tree (whenRUFLET_MRUBYorthird_party/mrubyis populated).build-ruflet-client.ymlrunsruby tools/mruby_patches_test.rbin Verify Ruflet Explorer, and a pull request that changes only that test triggers it. The push triggers are unchanged.Android note for the 16 KB-alignment work (D2, on hold, untouched): the owner's uncommitted
tools/build_android_vm_artifacts.shruns CMake without minirake and only checks thatbuild/host_vmexists. Abuild/host_vmgenerated after this change comes from a patched tree; one left over from before does not. One line before its CMake loop closes that:ruby "$RUNTIME/vm/patches/mruby_patches.rb" "$MRUBY".Behavior changes
None of these affect writing or running Ruflet apps, or
rufletCLI output. They affect only VM builds (tools/build_*_vm_artifacts.sh, or minirake/rake with avm/build_config/*.rb).third_party/mrubyin place. Any minirake or rake run that loads avm/build_config/*.rb(evenminirake -T) rewritesthird_party/mruby/src/vm.conce with the550d10ahunk. After that,git -C ruby_runtime/third_party/mruby statusshowsM src/vm.c, and the ruflet checkout showsm ruby_runtime/third_party/mruby. The gitlink and the*.rb.lockfiles do not change.git -C ruby_runtime/third_party/mruby checkout -- src/vm.cundoes it. Justification: this is how the bug fix reaches every build path without moving the pin. A VM built without it reads past the call frame.ruflet: applied mruby patch 0001-Fixed-heap-buffer-overflow-in-method_missing.patch. Later builds print nothing. Justification: it makes the in-place edit in (1) visible.git applyprovides the applied / pending / misfit check. Stopping with a clear message is better than shipping a VM without the fix.method_missingreceives the call's own keywords forname(*a, **k),name(*a, k: 1),name(...),name(0, *a, **k),name(*a, 9, **k, z: 0)and 15+ literal arguments with keywords. Today it gets none, an earlier call's, or stack garbage (see the probe below). This is the bug fix.send(:name, *a, **k)still passes the keywords as a trailing Hash, as on main: that is the pre-7b59b50behaviour, which this PR does not change.Verification (head
19e6fcd4; main merges re-verified below)VMs are scratch macOS arm64 builds made with
tools/build_apple_vm_artifacts.sh macos --output <scratch>, run from exported trees against fresh clones of mruby449627d. The harness was linked withRUFLET_VM_LIBRARY=<scratch>/libruflet_vm.a. Nothing was written toruby_runtime/*/Frameworksor a working checkout'sthird_party/mruby. This Mac has no Rosetta, so the scratch script copies build only arm64 (thefor archloop and thelipoinputs). The main VM was built fromdd924eb3and this PR's from76e95c53.git diffshows no change to the VM inputs (ruby_runtime,packages/ruflet_core/lib,packages/ruflet_server/lib,packages/ruflet_record/lib) from those to maina309af55and19e6fcd4. The harness was rebuilt and run from exports ofa309af55and19e6fcd4.a309af55src/vm.cafter the buildruflet:linescoped_helper_testmethod_missingprobe (13 call shapes, CRuby 0 bad)sendwith splat keywords, see 4 above)compat_testSystemExitundefined)regexp_testicon_deferral_test,ruflet_gem_test,ruflet_record_gem_test, in-process bridgeFor
regexp_test, a scratch copy with its aborting lines replaced bynilruns to the end on both VMs with identical output (1 of 108 assertions failed, already on main).Also run on the final head:
ruby tools/mruby_patches_test.rb: 8 runs, 0 failures, 0 skips withRUFLET_MRUBYset, on Ruby 4.0.5 and 3.4.5; 1 skip (pinned tree) without it. CI's new step in Verify Ruflet Explorer ran it on19e6fcd4: 8 runs, 0 failures, 1 skip.ios.rb), the hook madeif false(host_vm.rb), therequire_relativecommented out,applygiven a different root, a wrong fix that keeps the needle (argv[ci->n + 1]), the git check dropped, and the ceiling guard dropped.minirake -Twith each of the six configs (desktop_linuxanddesktop_windowsthrough thewith_host_buildwrapper) on a pristine449627d: each applies the patch once (src/vm.cmodified, the fixed line present), a second run prints nothing, and a relativeMRUBY_CONFIGworks. The lock files are unchanged.--checkexits 0 on the patched tree and 1 on a pristine one.:pendingon449627d,:appliedon72c9e5d, and an error (build stops) on upstream masterfc55b04.env -i HOME=$HOME PATH=<dir with only ruby> ruby ruby_runtime/vm/patches/mruby_patches.rb <pristine tree>): it prints the "git is required" message, exits 2 and leavessrc/vm.cuntouched.--checkdoes the same.ruby test/compat/compat.rb --jobs 4checked 234 goldens, exit 0.ruby -Ilib -Itest test/compat_goldens_test.rbgave 242 runs, 0 failures.ruby tools/build_apple_vm_artifacts_test.rb: 3 runs, 0 failures.a309af55(Test every public Page method; check client actions against their services #88) adds onlypackages/ruflet_core/testfiles. Its three new test files pass on this head, each run in its own process.minirake -Truns above show it patching the tree for each of them.Release checklist
sh tools/build_apple_vm_artifacts.sh apple --install, and Android, Linux and Windows with their builders (git on PATH), from a tree with this change. Commit the artifacts and manifests in the runtime release.ruby ruby_runtime/vm/patches/mruby_patches.rb --checkexits 0 after the build.72c9e5dor later, delete the patch. If it is left behind, it is skipped when the new tree has that exact hunk, and the build stops when the surrounding code has changed.Merges of main up to
bc45ad66(head1c4cbc62)The gate merged main six times:
9353817d: main9202eb0c(refactor: dispatch ruflet commands through a command registry (WP-00 R2) #77, Test every control, service and shipped extension against its wire contract #86)e3f7438e:a9b58473(fix: read client-synced control state like event.control.value #71)c00a7211:43f75822(refactor: add the Flutter client startup hook seam (WP-00 R3) #76)e5285ef3:bc69c0b3(ruflet_record: open-ended ranges in where (18.., ..17, ...18) no longer match nothing #107)b01d8fd6:3cb9418d(Stop single icon lookups from building the constant-name index #82)1c4cbc62:bc45ad66(fix: let ruflet.yaml's display_name win over the app_name ruflet new writes into services.yaml #112,packages/rufletCLI only)The PR's diff against main is byte-identical to
19e6fcd4's diff againsta309af55. Main changed these VM inputs:packages/ruflet_core/lib(#86, #71, #82) andpackages/ruflet_record/lib(#107; the macOS, iOS and host VMs link ruflet-record). It also changed two harness tests:client_state_readers_testis new (#71) andicon_deferral_testwas extended (#82).These were run on
b01d8fd6, from an export with a fresh mruby449627d:ruby tools/mruby_patches_test.rb: 8 runs, 0 failures on Ruby 4.0.5 and 3.4.5. It skips 1 test withoutRUFLET_MRUBYand none with it.tools/build_apple_vm_artifacts_test.rb: 3 runs, 0 failures.compat.rb --jobs 4checked 291 goldens, exit 0.compat_goldens_test.rbgave 299 runs, 0 failures.host_vm(minirakewithhost_vm.rb): exit 0.src/vm.cwas patched once, with a diff equal to the patch, and the build printed oneruflet: appliedline.packages/ruflet_record/test/mruby_smoke.rbon thatmrubyprintsruflet_record mruby sqlite smoke: ok.scoped_helper,compat,regexp,ruflet_gem,ruflet_record_gem,in_processand the probe are byte-identical to the19e6fcd4run.icon_deferral_testpasses ("all checks passed").client_state_readers_testpasses (346 assertions, exit 0).On
1c4cbc62, the VM inputs are identical tob01d8fd6(git diff b01d8fd6 1c4cbc62is empty forruby_runtime,packages/ruflet_core,packages/ruflet_server,packages/ruflet_record,toolsand.github), so the VM results above carry over. These were rerun on1c4cbc62:mruby_patches_test.rbgave 8 runs, 0 failures, 1 skip on Ruby 4.0.5 and 3.4.5.build_apple_vm_artifacts_test.rbgave 3 runs, 0 failures.compat.rb --jobs 4checked 292 goldens, exit 0.compat_goldens_test.rbgave 300 runs, 0 failures.