Data UI Backlog

Read-time eval in model text

validate-deploy-model-text (lisp/model.lisp) reads model text with read-from-string under SBCL's default *read-eval* t, so a #.(...) form runs code in the staging Model Bank image. Deploy reaches it with the deployer role. Generate reaches it with only ai-user, as soon as the LLM responds, so a prompt-injected description is a real path to code execution. A read of about 200 KB of nested parens exhausts the stack (a storage-condition, not caught by ignore-errors or Hunchentoot), which quits a --disable-debugger image. Flagged during the "Deployment cleanup" review.

Fix: add a new helper, read-model-text (lisp/aux.lisp). It caps length at 256K and builds a shadow copy of the text: strings become "" (\" and \\ allowed inside), ; comments are removed, and newlines are kept so lines still match. Any character in the shadow outside the allow-list (ASCII letters and digits, -, :, ., parens, whitespace, one leading ') rejects the model with its line number; nothing is deleted. The leading ' must be followed by (. Parens are counted on the shadow (balanced, depth cap 64, nothing after the closing paren). Every token must be a keyword, an integer, t, nil, or a simple float (digits.digits, at most 7 digits), which rejects 1e3, .5 and bare symbols before the read. Then the original text, comments included, is read with *read-eval* nil as a backstop, and a post-read data check backs up the token rule. Deploy writes the validated text verbatim instead of reprinting it with prin1. Deploy, Generate, set-model, and compile_model use it. top-level-model-field and read-llm-config get only *read-eval* nil. The plan also fixes an extra ) in models/test/nullable-fk-test.lisp, adds a "Lexical rules" section to docs/model-reference.md, and adds a new model-text test suite. Accepted residual risks: cumulative keyword interning, deep nesting in the two *read-eval*-only readers, and single-float precision. Plan: read-time-eval-plan.org.

Implemented per the plan. lisp/aux.lisp: read-model-text and its five helpers — model-text-shadow (iterative one-pass shadow: strings → "", ; comments dropped, newlines kept so shadow line N is text line N), valid-model-char-p / valid-model-shadow (allow-list chars, paren balance, depth 64, trailing content), valid-model-quote (one leading ' before (, no second quote — the atom-after-quote shape has balanced parens, so the quote rule is what catches it), model-text-token-p / model-text-float-shape-p / model-text-token-error / valid-model-tokens (keywords, integers, t=/=nil, simple floats digits.digits ≤7 digits — rejecting 1e3, .5, 1., +1, bare symbols, and package markers before the read, so bare symbols are never interned), valid-model-data (post-read backstop; dolist walk, recursion only into elements so depth ≤ paren depth), plus *model-text-max-length* 262144, *model-text-max-depth* 64, *model-text-max-float-digits* 7. The original text (comments included) is then read under *read-eval* nil. lisp/model.lisp: validate-deploy-model-text now leads with read-model-text on the original text (length cap and line numbers honest under a comment header) and keeps its comments-only and leading-quote messages as follow-on checks; deploy-model-write-file and deploy-model-async take the text and write it verbatim (no prin1 float re-spelling); the deploy hook threads the stored text through; read-llm-config binds *read-eval* nil; set-model's file method reads via read-model-text before any table work. lisp/deployment.lisp: top-level-model-field gets *read-eval* nil only. scripts/data-ui: compile_model's --eval reads through read-model-text. Fixture fix: one extra ) removed from models/test/nullable-fk-test.lisp (today's plain read never saw it). Tests: new tests/model-text-tests.lisp (24 tests / 100 checks: #. non-execution probes across read, validate, set-model (models/local/ probe file, deleted in unwind-protect), and read-llm-config; :temperature 0.3 parses; shadow string/comment blindness; escapes; disallowed chars; unterminated string; paren balance; quote rules; depth 64/65/100k; length 262144/262145 and cap-through-header; token accepts and both rejection messages; long-token message shape; wide list; every checked-in model reads equal to a plain *read-eval*-nil read; deploy write verbatim round trips incl. 0.0005 spelling) + run-model-text-tests in tests/helpers.lisp and run-tests; the two validate-deploy-model-text assertions in tests/generator-tests.lisp updated to the new messages (unclosed / quoted plist, one line each). Manual adversarial checks: top-level-model-field on a #. probe file → reader error, no marker; compile_model read path → validation-error, no marker; a full DRY_RUN deploy of a models/local/ model with simple floats → "Model compiled OK" and float spelling intact in the written file. Docs: docs/model-reference.md gains a Lexical rules section under File form, and pointers from the discrete-filter and :precision rules. Accepted residual risks per plan: cumulative keyword interning, deep nesting in the two *read-eval*-only readers, single-float precision. Full suite scripts/data-ui tests: 3051/3051 across 52 groups.

Slot
4900
Status
60 Done
Tags
mvp, backend, bug
Contributors
Donnie