Skip to content

Commit a6f3c8c

Browse files
luisleo526claude
andcommitted
ci: close the delta read 2's fail-open inputs on the CR-150 source gate
Guarded bounded admission now refuses, on raw text rather than a lexed view, every spelling where a lexer and a compiler can disagree: line splices (including whitespace, FF and VT before the newline) inside comments and literals, raw string literals and their prefixed forms, NUL, BOM, non-ASCII text and brace digraphs. A define naming a proof-file identifier is refused in every scanned file after splice joining, regardless of lexical context, and blank inventory scope members are now malformed (exit 2) instead of an ordinary finding. Header entries under include/ are refused bounded admission: a consumer's prior includes and build flags are not proven, so the form cannot be enforced from the proof files alone. Rewords the one admission sentence added by c989d59 in docs/ci.md (replacing its "in the participating source and fixed-input files" wording) to state the same rule the code now enforces. Co-Authored-By: Claude Code <[email protected]>
1 parent 7331cba commit a6f3c8c

3 files changed

Lines changed: 251 additions & 55 deletions

File tree

‎docs/ci.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1239,7 +1239,7 @@ jobs does not establish a runtime fix or dismiss a sanitizer failure.
12391239

12401240
The companion inventory is an explicitly reviewed snapshot, never generated by verification. On an authorized verification host, `python3 scripts/cr150_source_gate.py --root . --emit-site-inventory` prints a proposed JSON inventory to stdout; it is an authoring command, and its exit 0 is **not a tree verdict**. Capture it with the approved file workflow, inspect the identity additions/removals, and commit the reviewed file with the source change. Initial migration must use the unchanged scanned sources of the recorded baseline. `--emit-seed` continues to print missing entry groups; it does not authorize additions to the site inventory. Regenerating an inventory to hide a mutation is not verification.
12411241

1242-
`PASS(bounded)` requires source enforcement as well as metadata. Admission is intentionally limited to one initially empty local `std::vector` of scalar values, whose every growth call is a standalone `push_back`/`emplace_back` with a numeric literal argument, directly inside `if (v.size() < FixedLimit) v.push_back(1);` (or a brace block containing just that push). The guard must name that vector and exactly the entry's single fixed bound identifier. Every other use of the container is refused, including alias creation, passing it elsewhere, other mutations and shadow declarations. This small supported form avoids trying to infer arbitrary C++ control flow or conversion side effects. Member/global containers, nonempty initializers, loops inside the guarded branch, range growth, compound guards, capacity-only guards, arithmetic bound expressions and reserve/assign/resize are not admitted as bounded. In the participating source and fixed-input files, only `#pragma once`, the standard `<vector>`/`<cstddef>`/`<cstdint>` includes and the source's direct include of the fixed-input definition header are supported; macros, conditionals and other includes are refused. Unsupported shapes must remain OPEN.
1242+
`PASS(bounded)` requires source enforcement as well as metadata. Admission is intentionally limited to one initially empty local `std::vector` of scalar values, whose every growth call is a standalone `push_back`/`emplace_back` with a numeric literal argument, directly inside `if (v.size() < FixedLimit) v.push_back(1);` (or a brace block containing just that push). The guard must name that vector and exactly the entry's single fixed bound identifier. Every other use of the container is refused, including alias creation, passing it elsewhere, other mutations and shadow declarations. This small supported form avoids trying to infer arbitrary C++ control flow or conversion side effects. Member/global containers, nonempty initializers, loops inside the guarded branch, range growth, compound guards, capacity-only guards, arithmetic bound expressions and reserve/assign/resize are not admitted as bounded. Bounded entry files must live outside `include/` because header consumers' prior includes and build flags are unproven; the entry and fixed-input definition files are checked as raw text, refusing line splices, raw string markers, NUL/BOM/non-ASCII text, brace digraphs and every directive except `#pragma once`, the standard `<vector>`/`<cstddef>`/`<cstdint>` includes and the entry's direct include of its fixed-input header, and any define naming a proof-file identifier is refused in raw text joined across splices throughout the scanned files. Unsupported shapes must remain OPEN.
12431243

12441244
Declare a fixed input with `name`, `definition`, a required positive integer `value` and `fixed_before_bar0: true`. After stripping comments and literals, the definition must contain exactly one supported namespace/class-scope `const`/`constexpr` integer declaration initialized to that value. At class scope it must be `static`; a nonstatic const field can be initialized differently for each instance. A local constant, mutable declaration, or comment that merely spells a definition is insufficient. Bound names may not carry a growth axis. The entry needs `state: bounded`, `bound`, matching `bound_inputs`, and non-placeholder `lifetime`, `rollback`, `hash_reader` and `tests`. Expression syntax accepts integers, names, `+ - * /` and `min`/`max` for validation, but enforced admission currently supports only a single fixed name. A fixed name used outside its definition and recognized size guards is refused rather than resolving shadowing with a new parser.
12451245

‎scripts/cr150_source_gate.py‎

Lines changed: 32 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@
9797
'noexcept', 'override', 'final', 'throw', 'sizeof', 'typename', 'template'}
9898

9999
BLANK_CHARS = ' \t\r\n'
100+
SPLICE_RE = re.compile(r'\\[ \t\f\v\x00]*\n')
101+
DEFINE_RE = re.compile(r'(?<!\w)define(?:\s|/\*.*?\*/)*([A-Za-z_]\w*)', re.S)
100102

101103

102104
class GateError(Exception):
@@ -449,7 +451,7 @@ def _text(value, who: str, field: str, *, placeholder_ok: bool = False) -> str:
449451

450452
def _str_list(value, who: str, field: str, *, nonempty: bool = True) -> list[str]:
451453
if not isinstance(value, list) or (nonempty and not value) \
452-
or not all(isinstance(v, str) and v for v in value):
454+
or not all(isinstance(v, str) and v.strip() for v in value):
453455
raise GateError(f'{who}: field {field} must be a {"non-empty " if nonempty else ""}'
454456
'list of strings')
455457
return value
@@ -1037,17 +1039,6 @@ def _guarded_push(site: Site, code: str) \
10371039
(base + size_start, base + size_end))
10381040

10391041

1040-
def _directives(text: str):
1041-
"""Join translation-phase splices before lexing directives, including %:."""
1042-
# Keep this normalization out of Scanner._lex: the reviewed site identities
1043-
# still use the original physical lines and lexical brace paths.
1044-
text = re.sub(r'\\[ \t]*\r?\n', '', text)
1045-
for code, _, literal in cxxlex.lex_lines(text):
1046-
marker = re.match(r'\s*(?:#|%:)', code)
1047-
if marker:
1048-
yield '#' + code[marker.end():], literal
1049-
1050-
10511042
def bounded_issues(entry: dict, group: list[Site], sites: list[Site],
10521043
texts: dict[str, str], manifest: Manifest) -> list[tuple[str, int, str]]:
10531044
"""Fail closed outside the small enforced form; annotation alone never passes."""
@@ -1059,43 +1050,55 @@ def finding(site: Site, reason: str):
10591050

10601051
if eid in manifest.bound_errors:
10611052
return [finding(first, manifest.bound_errors[eid])]
1053+
if Path(entry['file']).parts[0] == 'include':
1054+
return [finding(first, 'header entries under include/ are outside guarded bounded '
1055+
'admission: prior includes and build flags are not proven')]
10621056
if not IDENT_RE.fullmatch(bound) or bound not in manifest.fixed:
10631057
return [finding(first, f'bound {bound!r}: guarded admission requires one fixed input identifier')]
10641058
fixed = manifest.fixed[bound]
10651059
if fixed['definition'] not in texts:
10661060
return [finding(first, 'fixed-input definition is outside the scanned source files')]
1067-
lexed = {rel: Scanner._lex(text) for rel, text in texts.items()}
10681061
fixed_header = str(fixed['definition']).removeprefix('include/')
10691062
proof_files = {entry['file'], fixed['definition']}
10701063
macro_names = {'push_back', 'emplace_back', 'size'}
10711064
for rel in sorted(proof_files):
1072-
body = lexed[rel][0]
1073-
# The bounded proof uses physical-line code and ordinary braces.
1074-
# Refuse alternate spellings rather than changing inventory identities.
1075-
if any(line.rstrip().endswith('\\') for line in body.splitlines()):
1065+
raw = texts[rel]
1066+
# These are context-free raw-text refusals, including inside comments
1067+
# and literals. Do not let a lexer/compiler disagreement admit a proof.
1068+
if '\x00' in raw:
1069+
return [finding(first, f'{rel}: NUL is outside guarded bounded admission')]
1070+
if '\ufeff' in raw:
1071+
return [finding(first, f'{rel}: BOM is outside guarded bounded admission')]
1072+
if not raw.isascii():
1073+
return [finding(first, f'{rel}: non-ASCII text is outside guarded bounded admission')]
1074+
if re.search(r'(?:u8|[LuU])?R"', raw):
1075+
return [finding(first, f'{rel}: raw string literals are outside guarded bounded admission')]
1076+
if SPLICE_RE.search(raw):
10761077
return [finding(first, f'{rel}: line continuation is outside guarded bounded admission')]
1077-
if re.search(r'<%|%>', body):
1078+
if re.search(r'<%|%>', raw):
10781079
return [finding(first, f'{rel}: brace digraphs are outside guarded bounded admission')]
10791080
# Keywords and scalar/type names can be macro-rewritten just like the
10801081
# receiver and bound. Include both proof files, not just five names.
1081-
macro_names.update(IDENT_RE.findall(body))
1082-
for directive, literal in _directives(texts[rel]):
1083-
if re.fullmatch(r'\s*#\s*pragma\s+once\s*', directive):
1082+
macro_names.update(IDENT_RE.findall(raw))
1083+
for marker in re.finditer(r'#|%:', raw):
1084+
directive = '#' + raw[marker.end():].split('\n', 1)[0]
1085+
if re.fullmatch(r'#\s*pragma\s+once\s*', directive):
10841086
continue
1085-
if re.fullmatch(r'\s*#\s*include\s*<(?:vector|cstddef|cstdint)>\s*', directive):
1087+
if re.fullmatch(r'#\s*include\s*<(?:vector|cstddef|cstdint)>\s*', directive):
10861088
continue
1087-
if rel == entry['file'] and re.fullmatch(r'\s*#\s*include\s*', directive) \
1088-
and literal.strip() == fixed_header:
1089+
if rel == entry['file'] and re.fullmatch(
1090+
rf'#\s*include\s*"{re.escape(fixed_header)}"\s*', directive):
10891091
continue
1090-
return [finding(first, 'macro/conditional preprocessing or unsupported includes '
1092+
return [finding(first, f'{rel}: macro/conditional preprocessing or unsupported includes '
10911093
'are outside guarded bounded admission')]
10921094
for rel, text in texts.items():
1093-
for directive, _ in _directives(text):
1094-
# cxxlex removes comments without inserting a separating space.
1095-
definition = re.match(r'#\s*define\s*([A-Za-z_]\w*)', directive)
1096-
if definition and definition.group(1) in macro_names:
1095+
# Raw strings can revert splices; comments can cross directive lines.
1096+
# Intentionally ignore lexical context and even the directive marker.
1097+
for definition in DEFINE_RE.finditer(SPLICE_RE.sub('', text)):
1098+
if definition.group(1) in macro_names:
10971099
return [finding(first, f'scanned file {rel} defines macro '
10981100
f'{definition.group(1)!r} used by guarded bounded admission')]
1101+
lexed = {rel: Scanner._lex(text) for rel, text in texts.items()}
10991102
declarations = [s for s in group if s.cls == 'decl']
11001103
if len(declarations) != 1:
11011104
return [finding(first, 'guarded admission requires exactly one local scalar-vector declaration')]

0 commit comments

Comments
 (0)