Tell the key buffers their size, not an offset past their end
jolt.ffi/write took (ptr type offset value) and now takes (ptr type value offset), with the offset trailing and optional — the babashka.ffi order, changed upstream in 4feca766. Jolt moved its own callers in that commit; these two did not move, and nothing said so, because the arity is still legal and both arguments are still integers. So `(ffi/write plen :size_t 0 32)` stopped meaning "this buffer is 32 bytes" and started meaning "store 0 at offset 32" — an eight-byte write thirty-two bytes past the end of an eight-byte block, immediately before EVP_PKEY_get_raw_public_key. slen is the same store sixty-four bytes out. What that cost was a heap glibc noticed later and elsewhere: `malloc(): unaligned tcache chunk detected`, aborting inside OpenSSL's own allocator on the TLS dial, with a backtrace that names ecx_export and nothing of frq's. The runtime bump two commits ago did not introduce this; it uncovered it. read still takes its offset third, and glimmer, glimmer-vidya and glimmer-tui call neither, so these were the only two sites. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
ca5b5a3 parent: 0ee8bba modified
src/frq/msgsig.jolt +2 -2 | @@ -122,7 +122,7 @@ | ||
| 122 | 122 | (let [pub (ffi/alloc 32) |
| 123 | 123 | plen (ffi/alloc (ffi/sizeof :size_t))] |
| 124 | 124 | (try |
| 125 | - (ffi/write plen :size_t 0 32) | |
| 125 | + (ffi/write plen :size_t 32) | |
| 126 | 126 | (when (= 1 (c-get-raw-pub pkey pub plen)) |
| 127 | 127 | (let [raw (ffi/read-array pub 32)] |
| 128 | 128 | (reset! signer |
| @@ -149,7 +149,7 @@ | ||
| 149 | 149 | ctx (c-md-ctx-new)] |
| 150 | 150 | (try |
| 151 | 151 | (ffi/write-array msg bs) |
| 152 | - (ffi/write slen :size_t 0 64) | |
| 152 | + (ffi/write slen :size_t 64) | |
| 153 | 153 | (when (and (= 1 (c-sign-init ctx ffi/null ffi/null ffi/null pkey)) |
| 154 | 154 | (= 1 (c-sign ctx sig slen msg n))) |
| 155 | 155 | (str "ed25519:" kid ":" (b64url (ffi/read-array sig (ffi/read slen :size_t))))) |
| @@ -122,7 +122,7 @@ | |||
| 122 | (let [pub (ffi/alloc 32) | 122 | (let [pub (ffi/alloc 32) |
| 123 | plen (ffi/alloc (ffi/sizeof :size_t))] | 123 | plen (ffi/alloc (ffi/sizeof :size_t))] |
| 124 | (try | 124 | (try |
| 125 | - (ffi/write plen :size_t 0 32) | 125 | + (ffi/write plen :size_t 32) |
| 126 | (when (= 1 (c-get-raw-pub pkey pub plen)) | 126 | (when (= 1 (c-get-raw-pub pkey pub plen)) |
| 127 | (let [raw (ffi/read-array pub 32)] | 127 | (let [raw (ffi/read-array pub 32)] |
| 128 | (reset! signer | 128 | (reset! signer |
| @@ -149,7 +149,7 @@ | |||
| 149 | ctx (c-md-ctx-new)] | 149 | ctx (c-md-ctx-new)] |
| 150 | (try | 150 | (try |
| 151 | (ffi/write-array msg bs) | 151 | (ffi/write-array msg bs) |
| 152 | - (ffi/write slen :size_t 0 64) | 152 | + (ffi/write slen :size_t 64) |
| 153 | (when (and (= 1 (c-sign-init ctx ffi/null ffi/null ffi/null pkey)) | 153 | (when (and (= 1 (c-sign-init ctx ffi/null ffi/null ffi/null pkey)) |
| 154 | (= 1 (c-sign ctx sig slen msg n))) | 154 | (= 1 (c-sign ctx sig slen msg n))) |
| 155 | (str "ed25519:" kid ":" (b64url (ffi/read-array sig (ffi/read slen :size_t))))) | 155 | (str "ed25519:" kid ":" (b64url (ffi/read-array sig (ffi/read slen :size_t))))) |