From 14d9aa9cbadaa80d2204e8bbca17d3132ec19a6a Mon Sep 17 00:00:00 2001 From: Ronald Tse Date: Tue, 17 Nov 2026 23:32:50 +0800 Subject: [PATCH 1/2] fix(isc): bind Maybe/Some/MaybeSome suffixes to the whole built body The runtime compiled an alias body of the form maybe(X + Y) into X-prime Y-optional - the optionality suffix bound to the body's LAST atom instead of the body, so the rule silently never matched (maps#292, 52 fuzz cases; ts/py/rs were the consistent reference). The wrap condition was inverted: only a single-character String body is its own atomic unit; every other body needs the non-capturing group. Failing spec + fixture pin the agreed outputs. --- lib/interscript/interpreter.rb | 11 +++++--- .../interscript/fixtures/fuzz/alias-maybe.isc | 10 +++++++ spec/interscript/isc/fuzz_findings_spec.rb | 27 +++++++++++++++++++ 3 files changed, 45 insertions(+), 3 deletions(-) create mode 100644 spec/interscript/fixtures/fuzz/alias-maybe.isc create mode 100644 spec/interscript/isc/fuzz_findings_spec.rb diff --git a/lib/interscript/interpreter.rb b/lib/interscript/interpreter.rb index 938c48c4..487719d1 100644 --- a/lib/interscript/interpreter.rb +++ b/lib/interscript/interpreter.rb @@ -296,10 +296,15 @@ def build_item i, target = nil, doc = @map if target == :par raise Interscript::SystemConversionError, "Can't use a MaybeSome in a #{target} context" end - if Interscript::Node::Item::String === i.data && i.data.data.length != 1 - "(?:" + build_item(i.data, target, doc) + ")" + resuffix - else + # maps#292 (WO20 fuzz): the optionality suffix must bind to the + # WHOLE built body, not to its last atom — an unwrapped body like + # `(?:x|y|z)[1-3]` + `?` made only `[1-3]` optional and the rule + # silently never matched. Only a single-character string body is + # its own atomic unit and may skip the group. + if Interscript::Node::Item::String === i.data && i.data.data.length == 1 build_item(i.data, target, doc) + resuffix + else + "(?:" + build_item(i.data, target, doc) + ")" + resuffix end when Interscript::Node::Item::CaptureRef if target == :par diff --git a/spec/interscript/fixtures/fuzz/alias-maybe.isc b/spec/interscript/fixtures/fuzz/alias-maybe.isc new file mode 100644 index 00000000..3f4218b1 --- /dev/null +++ b/spec/interscript/fixtures/fuzz/alias-maybe.isc @@ -0,0 +1,10 @@ +system "T:fuzz-alias-maybe:1" { + aliases { + a_chain = maybe(any(["x", "y", "z"]) + any("1".."3")) + } + stage main { + sequence { + sub a_chain "R" + } + } +} diff --git a/spec/interscript/isc/fuzz_findings_spec.rb b/spec/interscript/isc/fuzz_findings_spec.rb new file mode 100644 index 00000000..f10b37ee --- /dev/null +++ b/spec/interscript/isc/fuzz_findings_spec.rb @@ -0,0 +1,27 @@ +# frozen_string_literal: true + +require "interscript" + +# WO20 differential-fuzz finding (maps#292): an alias whose body is a +# top-level `maybe(...)` was miscompiled by the ruby reference runtime — +# the optionality suffix bound to the inner expression's LAST atom +# (`(?:x|y|z)[1-3]?`) instead of the whole body (`(?:(?:x|y|z)[1-3])?`), +# so the rule never matched and the transliteration silently returned the +# input unchanged. ts/py/rs were the consistent reference; these rows pin +# the agreed outputs (rs `iscrs transliterate` on the same fixture). +RSpec.describe "fuzz: alias body maybe(...)" do + let(:fixture_dir) { File.expand_path("../fixtures/fuzz", __dir__) } + + before do + allow(Interscript).to receive(:load_path).and_return([fixture_dir]) + allow(Interscript).to receive(:map_aliases).and_return({}) + end + + it "fires the rule for a real match" do + expect(Interscript.transliterate("alias-maybe", "y")).to eq("RyR") + end + + it "fires the rule with empty matches at every boundary (maps#292 repro)" do + expect(Interscript.transliterate("alias-maybe", "abc")).to eq("RaRbRcR") + end +end From e411ccfe8a89a116191141ae52e39f31fa3f8891 Mon Sep 17 00:00:00 2001 From: Ronald Tse Date: Tue, 17 Nov 2026 23:33:00 +0800 Subject: [PATCH 2/2] test(py): pin the WO20 parse-boundary families (maps#293, maps#295A) Re-verified every fuzz-filed family against origin/main before writing these: the nested-block, unknown-keyword, malformed-escape and zero-width-in-compound-from families already match ruby/ts/rs on the shared .parg grammar (the fuzz-era drift was closed by the generated parser work), and the note-text brace corruption no longer reproduces (the din-kaa evidence map parses to the same rule set clean or braced). The pins keep those boundaries from drifting back. One residual stays open on purpose: ruleset-inside-metadata is rejected here because the canonical .parg metadata_field production has no ruleset_block - the ruby/ts/rs acceptance is the lax side and needs the owner ruling the issue itself asks for; py rejecting is grammar-canonical, not a defect. --- interscript-py/tests/test_isc_parser.py | 82 +++++++++++++++++++++++++ 1 file changed, 82 insertions(+) diff --git a/interscript-py/tests/test_isc_parser.py b/interscript-py/tests/test_isc_parser.py index a1dea5bb..b7629db3 100644 --- a/interscript-py/tests/test_isc_parser.py +++ b/interscript-py/tests/test_isc_parser.py @@ -502,3 +502,85 @@ def test_duplicate_ruleset_declaration_error(self): 'system "s" { ruleset t { sub "a" "b" } ruleset t { sub "c" "d" } ' 'stage main { use t } }' ) + + +class TestParseBoundaryFuzzFamilies: + """WO20 fuzz families (maps#293) — the py parser's accept/reject + boundary must match ruby/ts/rs on every family the campaign filed. + Verified against origin/main 2026-11-17: the fuzz-era drift families + (nested blocks, unknown keywords, malformed escapes, zero-width + primitives in compound from) are already aligned with the shared + .parg grammar; these pins keep the boundary from drifting back. The + ruleset-in-metadata rejection is grammar-canonical (the .parg + metadata_field production has no ruleset_block) — ruby/ts/rs accept + it and that laxness is an owner ruling, not a py defect.""" + + def test_nested_parallel_in_sequence_rejected(self): + with pytest.raises(IscParseError): + parse( + 'system "s" { stage main { sequence { sub "a" "b" ' + 'parallel { sub "c" "d" } } } }' + ) + + def test_unknown_keyword_in_item_position_rejected(self): + with pytest.raises(IscParseError): + parse('system "s" { stage main { frobnicate "a" "b" } }') + + def test_malformed_escape_in_rule_string_rejected(self): + with pytest.raises(IscParseError): + parse('system "s" { stage main { sub "a\\q" "b" } }') + + def test_ruleset_inside_metadata_rejected(self): + with pytest.raises(IscParseError): + parse( + 'system "s" { metadata { ruleset probe { sub "a" "b" } } ' + 'stage main { sub "a" "b" } }' + ) + + def test_zero_width_primitive_in_compound_from_parses(self): + # maps#293 family B1: ruby/ts/rs parse-accept (then fail at + # execution with named logic errors); py must accept at parse too. + doc = parse( + 'system "s" { stage main { sequence { sub { ' + 'from word_boundary + capture(some("z")) + word_boundary ' + 'to "W" + ref(1) not_before "j" not_after "k" } } } }' + ) + seq = doc.stages[0].items[0] + assert isinstance(seq, SequenceBlock) and len(seq.rules) == 1 + + + +class TestNoteTextIsInert: + """WO20 fuzz finding (maps#295A): a `{` inside a metadata note string + used to corrupt the py parser's block/string scanning so the map + parsed a DIFFERENT rule set (silently altered transliteration output). + The fuzz evidence map (din-kaa with `standard's` -> `standa{d's`) now + parses to the same rule set as the clean map; this pin keeps metadata + free-text inert.""" + + BASE = ( + 'system "s" {\n' + ' metadata {\n' + " description { the standa%D's text layer }\n" + ' }\n' + ' tests { "б" -> "b" }\n' + ' stage main { parallel { sub "б" "b" } }\n' + '}\n' + ) + + def test_brace_in_note_text_does_not_alter_rules(self): + from interscript.executor import execute_stage as ex + + good = self.BASE.replace("%D", "r") + bad = self.BASE.replace("%D", "{") + for probe in ("б", "бб", "x"): + cm_good = isc_to_compiled_map(parse(good)) + cm_bad = isc_to_compiled_map(parse(bad)) + assert ex(cm_good, "main", probe) == ex(cm_bad, "main", probe) + + def test_brace_note_transliteration_matches_clean_map(self): + from interscript.executor import execute_stage as ex + + bad = self.BASE.replace("%D", "{") + cm = isc_to_compiled_map(parse(bad)) + assert ex(cm, "main", "б") == "b"