#286 prelude printer (fmt-print-vector/fmt-print-cons) has no cycle/depth guard — prin1 of a cyclic structure segfaults (stack overflow)

closed
Opened by atgreen

The REPL echo printer (ag-print-vector, repl.lisp) got a depth cap (cave#237) and now EQ cycle-detection (21f15f2), but the PRELUDE printer family (fmt-print-thing / fmt-print-vector / fmt-print-cons in stdlib.lisp) has NEITHER. Any user prin1/format ~S of a cyclic structure — e.g. an asdf SYSTEM instance (parent<->child cycles via mc instance vectors) — recurses unboundedly and SEGFAULTS on control-stack overflow.

Hit in practice: an instrumentation (prin1 ) where the key contained a SYSTEM instance segfaulted the whole load-system run.

Fix: port the ag-print-vector treatment to the prelude printer: depth cap + per-toplevel-print EQ visited set rendering revisits as #(...); ANSI-proper would be print-circle with #n= labels — the cap/ellipsis is the v0 stopgap. Watch the tree-shake rule (printer is warm-only, fine).

Comments (1)

atgreen3992796691

FIXED (commit in today's batch): three-part hardening — (1) instance arm before vectorp in the prelude dispatchers (the exponential asdf-instance case prints # now), (2) depth cap 64 + 65536-element spine cap with '...' elision across prelude AND REPL-echo printers (circular spines run at constant depth — only a length cap catches them), (3) depth/seen-set resets at public entries. Probes: circular list prin1-to-string => bounded 131KB (was SEGV); self-referential vector/instance bounded; normal output unchanged. Note: #230 (corrupt/out-of-heap cons) stays open — that failure is a garbage DEREF, not recursion; these caps reduce but don't eliminate it.