Skip to content

fix(isc): autoload CaptureRef; named error for unpaired refs in from (WO20 fuzz #864) - #866

Merged
ronaldtse merged 1 commit into
mainfrom
wo20-fix-ruby
Nov 16, 2026
Merged

ronaldtse merged 1 commit into
mainfrom
wo20-fix-ruby

Conversation

@ronaldtse

Copy link
Copy Markdown
Contributor

Summary

Fixes the ruby crash class found by the WO20 differential fuzz campaign (triage: interscript/maps#284, scripts/fuzz/TRIAGE.md) - interscript-ruby#864, 14 cases.

Root cause. Node::Item::CaptureRef exists (defined in item/capture.rb, next to CaptureGroup) but had no autoload entry in node/item.rb. Any map referencing ref(N) crashed with NameError: uninitialized constant Interscript::Node::Item::CaptureRef unless some earlier dependency parse had already referenced CaptureGroup - which loads the file and defines both classes as a side effect. The 27 corpus maps carrying to-position refs parse today only by that accident; the fuzz repros (isolated maps) crashed.

Fix.

  1. node/item.rb: the missing autoload :CaptureRef, "interscript/node/item/capture" - the constant is now order-independent.
  2. isc/node_adapter.rb: a capture ref whose capture group the from expression never opens is rejected at parse with a named MapLogicError - mirroring the WO18 G8 fn-literal-in-from convention (a named error, never an accidental exception; pre-fix this exact surface was the NameError, post-autoload-only it would be an accidental RegexpError: invalid backref at compile).

Scoping matters. A blanket from-position rejection would break a construct main explicitly pins: spec/interscript/isc/node_adapter_spec.rb runs from capture(any_character) + ref(1) (the geminate idiom) end-to-end. The gate is therefore pairing-based - Onigmo accepts any existing group number from any position (forward and nested refs included), so a ref(N) is valid iff the from expression opens >= N capture groups (CaptureGroup is the only capturing wrapper the interpreter emits). to-position refs (27 corpus maps) are untouched. Whether unpaired refs should instead be a run-time error like ts/py/rs is the owner-held cross-runtime question from the fuzz triage - this PR only removes the accidental exceptions.

Tests (spec/isc/fail_loud_spec.rb, WO20 section)

  • The campaign's minimized repro -> Interscript::MapLogicError: ref(1) in from position has no matching capture group (was NameError).
  • Nested some(ref(1)) -> same named rejection.
  • Paired ref in from stays legal and executable (geminate: чч -> ч).
  • CaptureRef autoload entry pinned in a fresh process (order-independent; the in-process form was order-fragile against suite pollution).
  • The issue repro re-run in a fresh process: MapLogicError, never NameError.
  • to-position ref parses and runs as a backreference (kk -> WkWk), in-process and in a fresh process.

Gates

  • Full bundle exec rake spec: 438 examples, 0 failures, 11 pending (SKIP_JS=1 SKIP_PYTHON=1, the CI configuration; the two cross-compiler execution legs are owned by the push matrix).
  • standardrb: clean on all touched files (the one remaining codemod.rb offense pre-exists on origin/main).
  • Corpus proof: all 428 maps + 7 libs parse with identical outcomes pre/post change (parse-all diff against a pristine 4c47eb5 worktree).
  • py subtree of this repo is untouched; re-verified green (450 passed / 8 skipped vs the 13,745-row rs-golden) and the py-vs-py parity driver holds at canonical 432/435 / raw 432/435 (--hand-rev 7a84260).
  • Fuzz smoke corpus (199 cases, four runtimes) green before and after; no smoke case regressed (the 7 classification flips in the smoke live in the py legs, fixed by the interscript-py PR for Provide option to give space between each transliterated segment in hk-yue-Han-Latn-govt, remove trailing space from map characters #44); smoke corpus untouched.

Fixes #864

WO20 fuzz fix (interscript-ruby#864, campaign: interscript/maps#284):
`ref(N)` in an ISC map crashed with NameError: uninitialized constant
Node::Item::CaptureRef - the class exists in item/capture.rb but had no
autoload entry, so the constant only resolved when an earlier dependency
parse happened to touch CaptureGroup first (27 corpus maps with
to-position refs escaped by that accident).

- node/item.rb: give CaptureRef its own autoload entry, making the
  constant order-independent.
- isc/node_adapter.rb: a ref whose capture group the from expression
  never opens is rejected at parse with a named MapLogicError - the
  WO18 G8 fn-literal-in-from convention (a named error, never an
  accidental exception; pre-fix this surface was the NameError). The
  pairing gate is count-based because Onigmo accepts any existing
  group number from any position: paired refs (the geminate idiom
  `from capture(any_character) + ref(1)`, pinned by node_adapter_spec)
  and to-position refs stay legal. Whether unpaired refs should be a
  run-time error like ts/py/rs is the owner-held cross-runtime
  question from the fuzz triage.

Corpus proof: all 428 maps + 7 libs parse with identical outcomes
pre/post change.
@ronaldtse
ronaldtse merged commit 8b2396e into main Nov 16, 2026
14 checks passed
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.

NameError: uninitialized constant Node::Item::CaptureRef on ref(N) in from position (parse crash)

1 participant