Add DEFLATE inflate/deflate builtins via system zlib (fixes #684)#693
Merged
InauguralPhysicist merged 1 commit intoJul 22, 2026
Merged
Conversation
…s#684) Four codecs as thin wrappers over the system zlib (-lz), two dual pairs in the InauguralSystems#677 sense: - inflate / deflate: raw DEFLATE (windowBits -15) — the ZIP member format, so .xlsx/.ods entries are readable from script. - zlib_inflate / zlib_deflate: zlib-wrapped; inflate uses windowBits 15+32, auto-detecting zlib AND gzip headers — that is what makes plain .gz files readable. Byte representation mirrors read_bytes/write_bytes exactly: a list of ints 0-255 (mod 256) or a buffer in, a fresh list of ints 0-255 out. Corrupt/truncated input raises a catchable `value` error, never a crash; decompressed output is capped at 256 MiB (`limit`, zip-bomb bound, matching the sandbox_run default budget). Gating preserves the zero-dependency minimal build via the existing EIGENSCRIPT_EXT_* mechanism (same pattern as `make http`): default OFF, `make zlib` opts in. Compiled without zlib the four names stay registered — so scripts feature-detect with try/catch and the sandbox fail-closed allowlist can name real builtins — but every call raises "compiled without zlib support". All four are pure bytes<->bytes and join SANDBOX_ALLOW. Tests: tests/test_inflate.eigs (22 checks) — round-trip identity for both pairs incl. empty and 8 KB inputs, fixed known-vectors generated by python's zlib (inflate pinned independently of our deflate), gzip auto-detect, buffer input, corrupt/truncated catchable errors, and the wrong-type error shape. run_all_tests.sh [123] probe-gates the section like [44] HTTP: the real suite runs only under `make zlib`; on minimal builds it instead asserts the stub raises the documented error. Suites: release minimal 3131/3131, release zlib 3152/3152, asan minimal 3135/3135, asan+zlib 3156/3156 (leaks on, all zero-fail). Co-Authored-By: Kimi K3 <noreply@kimi.com>
This was referenced Jul 22, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Implements #684: DEFLATE decompression (and its write-side duals) as thin wrappers over the system zlib, so scripts can read real-world
.xlsx/.odsZIP entries and.gzstreams.The builtins
inflate.xlsx/.odsentries)deflateinflatezlib_inflate.gzreadablezlib_deflateByte representation mirrors
read_bytes/write_bytesexactly (list of 0-255 ints or a buffer in, fresh list out). Corrupt/truncated input raises a catchablevalueerror, never a crash. Decompressed output is capped at 256 MiB (zip-bomb bound, matching thesandbox_rundefault budget) — a design choice not in the issue text; tune or drop freely. All four are inSANDBOX_ALLOW(pure bytes→bytes, no fs/proc/net/env access).Gating (zero-dependency build preserved)
EIGENSCRIPT_EXT_ZLIBmacro + a newmake zlibtarget, mirroring themake httpprecedent. Default OFF: every existing build target is byte-for-byte unchanged andbuild.shis untouched.One disclosed deviation from the extension precedent (deliberate): disabled extensions normally leave their builtins unregistered ("undefined variable"). Here the four builtins register unconditionally and the gated-out bodies raise a catchable
"<name>: compiled without zlib support (rebuild with make zlib)"— a clear, actionable error for scripts probing capability. Happy to switch to the unregistered convention if you prefer strict consistency. (Error kind isvalue— the closedErrKindset has no capability kind.)Tests + verification
tests/test_inflate.eigs(22 checks), wired as section[123]probe-gated exactly like[44]HTTP: minimal builds run a 1-check stub-contract test, zlib builds run the full 22. The gating can't misfire — the stub string only exists in the!EIGENSCRIPT_EXT_ZLIBcompilation branch.3131/3131, zlib3152/3152, ASan3135/3135, ASan+UBSan+zlib3156/3156— no sanitizer/leak reports.stdlib_index_check(+selftest),doc_drift_check,freestanding_checkall green.inflate's windowBits −15→15 fails all 22 checks.limiterror in <1 s.Maintainer-facing notes
make fulldoes not gain zlib (kept strictly to the opt-in mirror ofmake http) — say the word and I'll add-DEIGENSCRIPT_EXT_ZLIB=1 -lzthere.make zlibleg, so[123]exercises only the stub contract in CI until one is added.docs/BUILTINS.md:3says "199 core" builtins butsrc/builtins.cregistered 228 before this change (232 after) — stale count, not mechanically gated.Generated by Claude Fable 5 (brief, review), Kimi K3 (implementation)