Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

zlib: avoid converting Uint8Array instances to Buffer #39492

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions lib/zlib.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ const {
ObjectDefineProperties,
ObjectDefineProperty,
ObjectFreeze,
ObjectGetPrototypeOf,
ObjectKeys,
ObjectSetPrototypeOf,
ReflectApply,
Expand All @@ -60,7 +59,8 @@ const {
} = require('internal/util');
const {
isArrayBufferView,
isAnyArrayBuffer
isAnyArrayBuffer,
isUint8Array,
} = require('internal/util/types');
const binding = internalBinding('zlib');
const assert = require('internal/assert');
Expand Down Expand Up @@ -112,10 +112,9 @@ for (const ckey of ObjectKeys(codes)) {

function zlibBuffer(engine, buffer, callback) {
validateFunction(callback, 'callback');
// Streams do not support non-Buffer ArrayBufferViews yet. Convert it to a
// Streams do not support non-Uint8Array ArrayBufferViews yet. Convert it to a
// Buffer without copying.
if (isArrayBufferView(buffer) &&
ObjectGetPrototypeOf(buffer) !== Buffer.prototype) {
if (isArrayBufferView(buffer) && !isUint8Array(buffer)) {
buffer = Buffer.from(buffer.buffer, buffer.byteOffset, buffer.byteLength);
} else if (isAnyArrayBuffer(buffer)) {
buffer = Buffer.from(buffer);
Expand Down