Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 82 additions & 0 deletions interscript-py/tests/test_isc_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
11 changes: 8 additions & 3 deletions lib/interscript/interpreter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions spec/interscript/fixtures/fuzz/alias-maybe.isc
Original file line number Diff line number Diff line change
@@ -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"
}
}
}
27 changes: 27 additions & 0 deletions spec/interscript/isc/fuzz_findings_spec.rb
Original file line number Diff line number Diff line change
@@ -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
Loading