Replace cl-isaac with ironclad for connection ID generation - #458
Open
bhw-foss wants to merge 1 commit into
Open
Replace cl-isaac with ironclad for connection ID generation#458bhw-foss wants to merge 1 commit into
bhw-foss wants to merge 1 commit into
Conversation
cl-isaac's rand32 unconditionally decrements its (unsigned-byte 32) randcnt slot before checking for block exhaustion. Under (safety 2) the type check fires on the 0 -> -1 underflow, unwinds before the reset branch runs, and permanently wedges the PRNG -- causing clog-connection::random-hex-string to throw inside handle-new-connection and silently break connection bootstrap on long-running servers (upstream issue rabbibotton#12, PR rabbibotton#13 unmerged). cl-pass already pulls ironclad in transitively, and the Windows branch of random-hex-string already used ironclad. Drop cl-isaac entirely, declare ironclad explicitly, and collapse the platform conditional.
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.
I ran into this issue with sbcl declaim safety 2 and patched my project by overriding clog-connection::random-hex-string. Claude's diagnosis is below.
The bug
cl-isaac'srand32unconditionallydecfs itsrandcntslot(declared
(unsigned-byte 32)) before checking whether the256-word ISAAC block is exhausted:
cl-isaac compiles its own
isaac-32.lispunder(safety 2)(set inmake.lisp), so SBCL's typed-slot writer raisesTYPE-ERRORon theunderflow, unwinding
rand32before the(if (zerop c) ...)resetbranch ever runs.
randcntstays at 0 and the PRNG is permanentlywedged — every subsequent call traps in the same place.
How it manifests in CLOG
clog-connection::random-hex-stringthrows insidehandle-new-connection. The surroundinghandler-caseswallows theerror, the WebSocket upgrade completes, but the
(websocket-driver:send connection "clog['connection_id']='…'")andthe on-connect thread spawn never run — so the server sends 0 bytes
after the 101 handshake and the browser sits on an unbootstrapped body
forever. Restarting "fixes" it briefly because
*isaac-ctx*isrestored from the
save-lisp-and-dieimage with a non-zerorandcnt;after one ISAAC block (~256 connections) it wedges again.
Upstream is unresponsive — issue and PR open since 2023:
The fix
CLOG already called
ironclad:byte-array-to-hex-string+ironclad:random-dataon the Windows branch ofrandom-hex-string,and
cl-pass(already a direct dep) pullsironcladin transitively.This PR:
cl-isaacfromclog.asdand declaresironcladexplicitly,*isaac-ctx*defparameter (not exported — verifiedagainst the
defsection @clog-connectionexport list),random-hex-stringto a single platform-agnostic bodyusing the existing ironclad codepath.
Output contract is preserved: 32 lowercase hex chars (16 octets from
ironclad's default OS PRNG —
/dev/urandomon Unix,CryptGenRandomon Windows).Verification
Loaded
:clogclean in SBCL 2.5.2, then:— would have wedged the old cl-isaac path after ~256 calls under
(safety 2).