Skip to content

Commit 61b4a98

Browse files
aduh95targos
authored andcommitted
zlib: avoid converting Uint8Array instances to Buffer
PR-URL: #39492 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Zeyu Yang <himself65@outlook.com> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
1 parent 61261cd commit 61b4a98

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

lib/zlib.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ const {
3434
ObjectDefineProperties,
3535
ObjectDefineProperty,
3636
ObjectFreeze,
37-
ObjectGetPrototypeOf,
3837
ObjectKeys,
3938
ObjectSetPrototypeOf,
4039
ReflectApply,
@@ -60,7 +59,8 @@ const {
6059
} = require('internal/util');
6160
const {
6261
isArrayBufferView,
63-
isAnyArrayBuffer
62+
isAnyArrayBuffer,
63+
isUint8Array,
6464
} = require('internal/util/types');
6565
const binding = internalBinding('zlib');
6666
const assert = require('internal/assert');
@@ -109,10 +109,9 @@ for (const ckey of ObjectKeys(codes)) {
109109
function zlibBuffer(engine, buffer, callback) {
110110
if (typeof callback !== 'function')
111111
throw new ERR_INVALID_ARG_TYPE('callback', 'function', callback);
112-
// Streams do not support non-Buffer ArrayBufferViews yet. Convert it to a
112+
// Streams do not support non-Uint8Array ArrayBufferViews yet. Convert it to a
113113
// Buffer without copying.
114-
if (isArrayBufferView(buffer) &&
115-
ObjectGetPrototypeOf(buffer) !== Buffer.prototype) {
114+
if (isArrayBufferView(buffer) && !isUint8Array(buffer)) {
116115
buffer = Buffer.from(buffer.buffer, buffer.byteOffset, buffer.byteLength);
117116
} else if (isAnyArrayBuffer(buffer)) {
118117
buffer = Buffer.from(buffer);

0 commit comments

Comments
 (0)