Skip to content

fix: three Node.js compat bugs in node:crypto and node:buffer - #6923

Open
Sertug17 wants to merge 1 commit into
cloudflare:mainfrom
Sertug17:fix/crypto-and-buffer-compat-bugs-v2
Open

fix: three Node.js compat bugs in node:crypto and node:buffer#6923
Sertug17 wants to merge 1 commit into
cloudflare:mainfrom
Sertug17:fix/crypto-and-buffer-compat-bugs-v2

Conversation

@Sertug17

Copy link
Copy Markdown

Fixes three Node.js compatibility bugs found during manual code review.

Changes

1. node:cryptoCipheriv.prototype.update default encoding

Fixes#6920

cipher.update('string') without inputEncoding now defaults to 'utf8' instead of throwing ERR_INVALID_ARG_VALUE, matching Node.js behavior.

2. node:cryptoHmac.prototype.digest finalization

Fixes#6921

Calling hmac.digest() a second time now throws ERR_CRYPTO_HASH_FINALIZED instead of silently returning an empty Buffer, matching Hash.prototype.digest and Node.js behavior.

3. node:bufferBuffer.alloc / allocUnsafe off-by-one

Fixes#6922

Changed size >= kMaxLength to size > kMaxLength so that Buffer.alloc(kMaxLength) no longer incorrectly throws ERR_OUT_OF_RANGE. The internal createBuffer function already used > — this makes alloc consistent.

@Sertug17
Sertug17 requested review from a team as code ownersAugust 6, 2026 18:24
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment