summaryrefslogtreecommitdiff
path: root/build
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-19 18:21:17 -0300
committerGabriel Schneider <[email protected]>2026-11-19 18:22:50 -0300
commite4f99d2370c8b44e76b541826d91356d86090f53 (patch)
treef80e48017b1c33313dfcb222685d560251c3d9f8 /build
parentcbc9634091cf314d9cafeeb36ff274979d1cbc8f (diff)
downloadpardes-e4f99d2370c8b44e76b541826d91356d86090f53.tar.gz
pardes-e4f99d2370c8b44e76b541826d91356d86090f53.zip
build: mvzr's reads past a pattern cut short are patched as it is fetched, where pardes patches it already (build/patches.zig: eight edits that check the pattern's end before each read in a count, a byte escape and a class; unreported upstream as of its trunk 3efcfe33; docs/mvzr-bounds.md is the report), so the walk of the pattern that core/regexp.zig made to refuse them beforehand goes (55 lines: the dependency is fixed, not guarded, and no fork is needed); the test of every such pattern stays and aborts without the edits (index out of bounds: index 2) and passes with them; the edits checked to reproduce the patch proven on 5.4M patterns byte for byte; tui core-test 842/985 (143 skipped)
Co-Authored-By: Claude Fable 5.2 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
Diffstat (limited to 'build')
-rw-r--r--build/patches.zig19
1 files changed, 19 insertions, 0 deletions
diff --git a/build/patches.zig b/build/patches.zig
index 5e120345..d5ac7372 100644
--- a/build/patches.zig
+++ b/build/patches.zig
@@ -274,6 +274,14 @@ pub fn ghosttyKitty(b: *std.Build, patch: *std.Build.Step.Compile, dep: *std.Bui
/// upstream). A class's range ending at `\xff` counted to 256 in a u8, an
/// overflow (a panic in a safe build, a runaway loop in a fast one):
/// `[\x80-\xff]` in any search took the editor down.
+/// - compile() read past the end of a pattern that stops inside a count
+/// (`a{`, `a{,1`, `a{1`, `a{1,`, `a{1,2`), a byte escape (`\x`, `{\\x`)
+/// or a class (`[\`, `[\x`, `[\x41`, `[\\x]`): a panic in a safe build
+/// on the second key of a search for `a{2}`; in a fast one the bytes
+/// after the pattern decided what it meant, so a session and its client
+/// could compile one typed pattern differently. Unreported upstream as
+/// of 3efcfe33 (its trunk on 2026-11-19); docs/mvzr-bounds.md is the
+/// report for it.
const mvzr_edits = [_]Edit{
.{
.old = "fn matchPattern(patt: []const RegOp, sets: []const CharSet, haystack: []const u8, i_in: usize) ?OpMatch {\n",
@@ -326,6 +334,17 @@ const mvzr_edits = [_]Edit{
\\
,
},
+ // A pattern cut short inside a count, a byte escape or a class: each
+ // read checks the pattern's end first (a bad string, as its other
+ // malformed patterns are).
+ .{ .old = "fn parseHex(in: []const u8) !u8 {\n", .new = "fn parseHex(in: []const u8) !u8 {\n if (in.len < 2) return error.BadString;\n" },
+ .{ .old = " i += 1;\n if (in[i] == ',') { // {,?\n", .new = " i += 1;\n if (i == in.len) {\n bad_string = true;\n break :dispatch;\n }\n if (in[i] == ',') { // {,?\n" },
+ .{ .old = " if (in[i] == '}') { // {,N}\n", .new = " if (i < in.len and in[i] == '}') { // {,N}\n" },
+ .{ .old = " i += d1;\n if (in[i] == ',') { // {M,?\n i += 1;\n if (in[i] == '}') { // {M,}\n", .new = " i += d1;\n if (i == in.len) {\n bad_string = true;\n break :dispatch;\n }\n if (in[i] == ',') { // {M,?\n i += 1;\n if (i < in.len and in[i] == '}') { // {M,}\n" },
+ .{ .old = " i += d2;\n if (in[i] != '}') {\n", .new = " i += d2;\n if (i == in.len or in[i] != '}') {\n" },
+ .{ .old = "fn valueFor(in: []const u8) ?u8 {\n", .new = "fn valueFor(in: []const u8) ?u8 {\n if (in.len == 0) return null;\n" },
+ .{ .old = " return parseHex(in[1..4]) catch return null;\n", .new = " return parseHex(in[1..3]) catch return null;\n" },
+ .{ .old = " if (i == in.len or in[i] != ']') {\n return BadString;\n", .new = " if (i >= in.len or in[i] != ']') {\n return BadString;\n" },
.{ .old = "for (c1..c2 + 1) |c_range|", .new = "for (c1..@as(usize, c2) + 1) |c_range|" },
.{ .old = "[1]RegOp{.{ .unused = {} }} ** ops", .new = "@splat(.{ .unused = {} })" },
.{ .old = "[1]CharSet{.{ .low = 0, .hi = 0 }} ** char_sets", .new = "@splat(.{ .low = 0, .hi = 0 })" },