Skip to content

Carry Hash and Hmac values through unknown and any slots - #1257

Open
ctate wants to merge 5 commits into
mainfrom
ctate/carry-hash-hmac-cc44f6
Open

ctate wants to merge 5 commits into
mainfrom
ctate/carry-hash-hmac-cc44f6

Conversation

@ctate

@ctate ctate commented Oct 18, 2026

Copy link
Copy Markdown
Collaborator
  • Hash and Hmac values in unknown/any slots and untyped JavaScript keep their identity and support update(), digest() and Hash's copy(), called or read as values, as in Node 24.22; their stream members there throw a coded SC2020 error.
  • Method calls on native handles read through as any dispatch through the handle, and copy() on an Hmac throws Node's TypeError.
  • 500,000 SHA-256 digests through an untyped JavaScript parameter take 201 ms, against 470 ms in Node; the typed Hash and Hmac paths and bench:runtime are unchanged, with no binary size change.

A Hash or Hmac that flows into an unknown or any slot, or into untyped
JavaScript code, is now a native handle (Hash or Hmac) instead of a
compile error. The handle keeps the value's identity, so a cast back to
Hash or Hmac answers the same value. update(), digest() and Hash's
copy() dispatch through it, called directly or read as values: update
is one function for Hash and Hmac and digest is one per class, as in
Node 24.22, and update() answers the receiver. The stream and event
members throw a coded SC2020 error there, as do the methods called with
another receiver; other names read as undefined.

The to-dyn conversion boxes a Hash or Hmac through
scr_crypto_hash_to_dyn, which installs the handle ops on first use, so
programs that never box one link none of the handle code.

A native handle read through `as any` now dispatches its method calls
through the handle. Calling copy() on an Hmac throws Node's TypeError
("mac.copy is not a function") after the arguments are evaluated,
instead of the method-call fence.

Corpus 5768 and 5769 cover the TypeScript and JavaScript forms against
Node 24.22, and errors.test.ts covers the SC2020 cases. corpus-costs.json
records their plain and sanitized costs.
@vercel

vercel Bot commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
scriptc Ready Ready Preview, v0 Oct 18, 2026 2:20pm UTC

"Hash and Hmac methods called with a receiver other than their own Hash or Hmac have no "
"lowering";
scr_throw_error_msg_code(SCR_ERR_ERROR, msg, sizeof msg - 1, "SC2020");
}

@vercel vercel Bot Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

scr_crypto_hash_dyn_invoke passes snprintf's return value (would-be length) as the string length to scr_throw_error_msg, causing an out-of-bounds stack over-read when the callee text makes the message exceed the 160-byte buffer.

Fix on Vercel

This branch was successfully deployed

1 active deployment
Preview — 90c697f7 Deployed Oct 18, 2026 by vercel[bot]
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