mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 10:59:27 +00:00
zlib: remove prototype primordials usage
# Conflicts: # lib/zlib.js PR-URL: https://github.com/nodejs/node/pull/54695 Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com> Reviewed-By: Robert Nagy <ronagy@icloud.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ruy Adorno <ruy@vlt.sh> Reviewed-By: Moshe Atlow <moshe@atlow.co.il> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com> Reviewed-By: Matthew Aitken <maitken033380023@gmail.com>
This commit is contained in:
parent
59c7c55aad
commit
c42d8461b0
@ -10,6 +10,7 @@ important than reliability against prototype pollution:
|
|||||||
* `node:http`
|
* `node:http`
|
||||||
* `node:http2`
|
* `node:http2`
|
||||||
* `node:tls`
|
* `node:tls`
|
||||||
|
* `node:zlib`
|
||||||
|
|
||||||
Usage of primordials should be preferred for new code in other areas, but
|
Usage of primordials should be preferred for new code in other areas, but
|
||||||
replacing current code with primordials should be
|
replacing current code with primordials should be
|
||||||
|
@ -498,6 +498,7 @@ export default [
|
|||||||
'lib/internal/http.js',
|
'lib/internal/http.js',
|
||||||
'lib/internal/http2/*.js',
|
'lib/internal/http2/*.js',
|
||||||
'lib/tls.js',
|
'lib/tls.js',
|
||||||
|
'lib/zlib.js',
|
||||||
],
|
],
|
||||||
rules: {
|
rules: {
|
||||||
'no-restricted-syntax': [
|
'no-restricted-syntax': [
|
||||||
|
50
lib/zlib.js
50
lib/zlib.js
@ -23,21 +23,16 @@
|
|||||||
|
|
||||||
const {
|
const {
|
||||||
ArrayBuffer,
|
ArrayBuffer,
|
||||||
ArrayPrototypeForEach,
|
MathMax,
|
||||||
ArrayPrototypeMap,
|
|
||||||
ArrayPrototypePush,
|
|
||||||
FunctionPrototypeBind,
|
|
||||||
MathMaxApply,
|
|
||||||
NumberIsNaN,
|
NumberIsNaN,
|
||||||
ObjectDefineProperties,
|
ObjectDefineProperties,
|
||||||
ObjectDefineProperty,
|
ObjectDefineProperty,
|
||||||
|
ObjectEntries,
|
||||||
ObjectFreeze,
|
ObjectFreeze,
|
||||||
ObjectKeys,
|
ObjectKeys,
|
||||||
ObjectSetPrototypeOf,
|
ObjectSetPrototypeOf,
|
||||||
ReflectApply,
|
ReflectApply,
|
||||||
StringPrototypeStartsWith,
|
|
||||||
Symbol,
|
Symbol,
|
||||||
TypedArrayPrototypeFill,
|
|
||||||
Uint32Array,
|
Uint32Array,
|
||||||
} = primordials;
|
} = primordials;
|
||||||
|
|
||||||
@ -130,10 +125,11 @@ function zlibBuffer(engine, buffer, callback) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function zlibBufferOnData(chunk) {
|
function zlibBufferOnData(chunk) {
|
||||||
if (!this.buffers)
|
if (!this.buffers) {
|
||||||
this.buffers = [chunk];
|
this.buffers = [chunk];
|
||||||
else
|
} else {
|
||||||
ArrayPrototypePush(this.buffers, chunk);
|
this.buffers.push(chunk);
|
||||||
|
}
|
||||||
this.nread += chunk.length;
|
this.nread += chunk.length;
|
||||||
if (this.nread > this._maxOutputLength) {
|
if (this.nread > this._maxOutputLength) {
|
||||||
this.close();
|
this.close();
|
||||||
@ -442,7 +438,7 @@ function processChunkSync(self, chunk, flushFlag) {
|
|||||||
if (have > 0) {
|
if (have > 0) {
|
||||||
const out = buffer.slice(offset, offset + have);
|
const out = buffer.slice(offset, offset + have);
|
||||||
offset += have;
|
offset += have;
|
||||||
ArrayPrototypePush(buffers, out);
|
buffers.push(out);
|
||||||
nread += out.byteLength;
|
nread += out.byteLength;
|
||||||
|
|
||||||
if (nread > self._maxOutputLength) {
|
if (nread > self._maxOutputLength) {
|
||||||
@ -700,9 +696,10 @@ Zlib.prototype.params = function params(level, strategy, callback) {
|
|||||||
checkRangesOrGetDefault(strategy, 'strategy', Z_DEFAULT_STRATEGY, Z_FIXED);
|
checkRangesOrGetDefault(strategy, 'strategy', Z_DEFAULT_STRATEGY, Z_FIXED);
|
||||||
|
|
||||||
if (this._level !== level || this._strategy !== strategy) {
|
if (this._level !== level || this._strategy !== strategy) {
|
||||||
this.flush(Z_SYNC_FLUSH,
|
this.flush(
|
||||||
FunctionPrototypeBind(paramsAfterFlushCallback, this,
|
Z_SYNC_FLUSH,
|
||||||
level, strategy, callback));
|
paramsAfterFlushCallback.bind(this, level, strategy, callback),
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
process.nextTick(callback);
|
process.nextTick(callback);
|
||||||
}
|
}
|
||||||
@ -782,13 +779,10 @@ function createConvenienceMethod(ctor, sync) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
const kMaxBrotliParam = MathMaxApply(ArrayPrototypeMap(
|
const kMaxBrotliParam = MathMax(
|
||||||
ObjectKeys(constants),
|
...ObjectEntries(constants)
|
||||||
(key) => (StringPrototypeStartsWith(key, 'BROTLI_PARAM_') ?
|
.map(({ 0: key, 1: value }) => (key.startsWith('BROTLI_PARAM_') ? value : 0)),
|
||||||
constants[key] :
|
);
|
||||||
0),
|
|
||||||
));
|
|
||||||
|
|
||||||
const brotliInitParamsArray = new Uint32Array(kMaxBrotliParam + 1);
|
const brotliInitParamsArray = new Uint32Array(kMaxBrotliParam + 1);
|
||||||
|
|
||||||
const brotliDefaultOpts = {
|
const brotliDefaultOpts = {
|
||||||
@ -799,9 +793,9 @@ const brotliDefaultOpts = {
|
|||||||
function Brotli(opts, mode) {
|
function Brotli(opts, mode) {
|
||||||
assert(mode === BROTLI_DECODE || mode === BROTLI_ENCODE);
|
assert(mode === BROTLI_DECODE || mode === BROTLI_ENCODE);
|
||||||
|
|
||||||
TypedArrayPrototypeFill(brotliInitParamsArray, -1);
|
brotliInitParamsArray.fill(-1);
|
||||||
if (opts?.params) {
|
if (opts?.params) {
|
||||||
ArrayPrototypeForEach(ObjectKeys(opts.params), (origKey) => {
|
ObjectKeys(opts.params).forEach((origKey) => {
|
||||||
const key = +origKey;
|
const key = +origKey;
|
||||||
if (NumberIsNaN(key) || key < 0 || key > kMaxBrotliParam ||
|
if (NumberIsNaN(key) || key < 0 || key > kMaxBrotliParam ||
|
||||||
(brotliInitParamsArray[key] | 0) !== -1) {
|
(brotliInitParamsArray[key] | 0) !== -1) {
|
||||||
@ -939,10 +933,12 @@ ObjectDefineProperties(module.exports, {
|
|||||||
|
|
||||||
// These should be considered deprecated
|
// These should be considered deprecated
|
||||||
// expose all the zlib constants
|
// expose all the zlib constants
|
||||||
for (const bkey of ObjectKeys(constants)) {
|
for (const { 0: key, 1: value } of ObjectEntries(constants)) {
|
||||||
if (StringPrototypeStartsWith(bkey, 'BROTLI')) continue;
|
if (key.startsWith('BROTLI')) continue;
|
||||||
ObjectDefineProperty(module.exports, bkey, {
|
ObjectDefineProperty(module.exports, key, {
|
||||||
__proto__: null,
|
__proto__: null,
|
||||||
enumerable: false, value: constants[bkey], writable: false,
|
enumerable: false,
|
||||||
|
value,
|
||||||
|
writable: false,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user