Repository navigation
fix(response): send raw bytes of non-Uint8Array typed arrays in res.send() - #7542
princejain756 wants to merge 1 commit into
Conversation
|
I reviewed this together with #7574 (which carries this same commit) and #7511. The fix looks correct to me. Converting every non-Buffer A few notes:
|
…end() A non-Buffer ArrayBuffer view reached res.end() unconverted, which 500s on small payloads, or passed through Buffer.from(view), which writes one byte per element instead of the view's bytes, silently truncating values like 0x0102 to 0x02. Wrap any non-Buffer view in a Buffer sharing its memory, so Content-Length, ETag and the body all agree on the raw bytes. Fixes expressjs#7538
ca6d202 to
9d49e4a
Compare
|
Good call on both points @Gustavo-Luiz2304. Building the |
|
There are 5 open PRs for this now, so I ran the same bodies through all of them (etag on and off) to compare:
I think this one (or #7574, since it's the same commit with more tests) is the right base. About the
} else if (ArrayBuffer.isView(chunk) || isAnyArrayBuffer(chunk)) {
if (isAnyArrayBuffer(chunk)) chunk = Buffer.from(chunk)
|
|
Thanks for running that matrix across all 5 PRs @dvmhmdsd, that comparison is super helpful. Agreed on the For raw |
res.send()mishandlesArrayBufferviews that are notUint8Array:res.end()rejects the view and returns 500Buffer.from(view)writes one byte per element, so0x0102reaches the wire as0x02, andContent-Length/ETagdisagree with the bodyAny non-Buffer view is now wrapped in a
Buffersharing its memory before length, ETag and write, so the raw bytes are sent as-is.Uint8ArrayandDataViewinputs take the same path and produce identical output.Fixes #7538