FrankenNumPy

Docs/Evidence

Security Model

FrankenNumPy's security posture covers more than memory safety.

  • Safe-Rust numeric core. 10 of the 11 implementation crates declare #![forbid(unsafe_code)] and contain zero hand-written unsafe. The 11th (fnp-python) does not declare the lint: PyO3's procedural macros expand to unsafe at the cdylib boundary, and crates/fnp-python/src/lib.rs contains 67 audited unsafe blocks/items (consolidated from 1,250 in bead deadlock-audit-rc0923-epic-71qy3.21 by encapsulating ~1,000 PyBuffer / ReadOnlyCell / PyArrayObject slice views behind readonly_cells_as_slice, slice_as_readonly_cells, PyBufferExt, and NdarrayRaw), with #![forbid(unsafe_op_in_unsafe_fn)], #![deny(clippy::undocumented_unsafe_blocks)], 100% // SAFETY: comment coverage, and a structural budget ceiling enforced by fnp_python_unsafe_blocks_are_encapsulated_and_documented in crates/fnp-conformance/tests/codebase_hygiene.rs. The codebase_hygiene suite also enforces that the other 10 crates stay completely unsafe-free.
  • Fail-closed by default. Unknown wire formats, unrecognized dtype descriptors, future metadata-version markers, and metadata schema violations cause explicit errors, not silent fallbacks.
  • Bounded resource consumption. NPY header caps at 64 KB. NPZ archives cap at 4,096 members and 2 GiB uncompressed. Text I/O caps at 16,777,216 elements. Memmap validation retries cap at 64. These prevent denial of service via crafted inputs to the fnp-io Rust API. From Python they guard fnp_python.load in hardened mode only: strict mode decodes a plain .npy path through fnp-io and gives file-like objects and every .npz to numpy.load, as NumPy would (ledger row DIV-HARDENED-LOAD-BOUNDS).
  • Pickle rejection. Object dtype arrays that could execute arbitrary code during deserialization require explicit allow_pickle=true, matching NumPy's security gate.
  • Adversarial conformance. The security gate (run_security_gate) tests exploit scenarios from a versioned threat matrix mapped to specific parser / IO / shape-validation boundaries.
  • No production code mocks or stubs. Structurally enforced by crates/fnp-conformance/tests/codebase_hygiene.rs — 12 #[test] functions, which fail CI if unimplemented!, todo!, FIXME, HACK, XXX, stub comments, panic!("not implemented"), dbg!() in library code, or #[allow(unused_*)] in library code appear in crates/*/src/; four more keep hand-written unsafe out of every crate but fnp-python, forbid allow(unsafe_code) overrides and std::arch intrinsics in every crate, and keep ufunc-shadowed #[pyfunction]s unregistered, and test_count_sanity_check asserts the workspace stays above 6,000 #[test] functions. The no_allow_unused_in_library_code test is the subtle one: the unused_* warning family is what catches stale code paths that would otherwise rot silently, so suppressing it via #[allow(unused_*)] is treated as a stub marker. The human-readable audit at docs/planning/audit_numpy_mocks.md (dated 2026-05-14) is the companion document with per-site analysis. It predates the current panic-site count; see the Error Taxonomy section.

This section in the README on GitHub