Skip to content

Harden runtime type validation system#25

Merged
wolfy-j merged 1 commit intomainfrom
fix/runtime-type-validation-hardening
Mar 21, 2026
Merged

Harden runtime type validation system#25
wolfy-j merged 1 commit intomainfrom
fix/runtime-type-validation-hardening

Conversation

@wolfy-j
Copy link
Contributor

@wolfy-j wolfy-j commented Mar 21, 2026

  • Fix table? validation rejecting valid tables (Ref("table") unresolved from manifest, builtin type fallback added to resolveRuntimeType)
  • Add structured validation errors via *Error with Kind=Invalid and details map (field, expected, got, constraint) accessible from Lua through err:kind(), err:details(), err:message()
  • Fast-path :is() using zero-alloc validateValue on success, only computing error details on failure (2.6x speedup, 0 allocs on pass)
  • Handle all 32 typ.Type implementations in runtime validation: Recursive, Sum, Platform, Intersection, Ref, Annotated nil-inner
  • Nil-safe String()/Kind() on all compound types (Record, Map, Array, Tuple, Union, Intersection, Optional, Annotated) to prevent segfaults from corrupted manifests
  • Guard all reflection methods (elem, key, val, inner, ret, fields, variants, params) and type comparison against nil internals
  • Recursion depth limit (64) on validation to prevent stack overflow from malformed recursive types
  • Map validation checks Array part for number-keyed maps
  • Record validation checks MapComponent for records with map components
  • Type IO decoder hardening: maxSliceLen reduced to 64, depth limit 32, node budget 1024, missing checkSliceLen in readCondition
  • CI: add fuzz, race, and benchmark jobs

- Fix table? validation rejecting valid tables (Ref("table") unresolved
  from manifest, builtin type fallback added to resolveRuntimeType)
- Add structured validation errors via *Error with Kind=Invalid and
  details map (field, expected, got, constraint) accessible from Lua
  through err:kind(), err:details(), err:message()
- Fast-path :is() using zero-alloc validateValue on success, only
  computing error details on failure (2.6x speedup, 0 allocs on pass)
- Handle all 32 typ.Type implementations in runtime validation:
  Recursive, Sum, Platform, Intersection, Ref, Annotated nil-inner
- Nil-safe String()/Kind() on all compound types (Record, Map, Array,
  Tuple, Union, Intersection, Optional, Annotated) to prevent segfaults
  from corrupted manifests
- Guard all reflection methods (elem, key, val, inner, ret, fields,
  variants, params) and type comparison against nil internals
- Recursion depth limit (64) on validation to prevent stack overflow
  from malformed recursive types
- Map validation checks Array part for number-keyed maps
- Record validation checks MapComponent for records with map components
- Type IO decoder hardening: maxSliceLen reduced to 64, depth limit 32,
  node budget 1024, missing checkSliceLen in readCondition
- CI: add fuzz, race, and benchmark jobs

512 tests, 115M+ fuzz executions across 4 fuzzers (Lua source types,
manifest types, corrupted type bytes, corrupted manifests), zero crashes.
@wolfy-j wolfy-j merged commit 7582295 into main Mar 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant