Version
latest main branch
Platform
Subsystem
zlib
What steps will reproduce the bug?
const zlib = require('node:zlib');
const cases = [
{
label: 'string',
pledgedSrcSize: '1',
input: Buffer.alloc(42),
},
{
label: 'null',
pledgedSrcSize: null,
input: Buffer.alloc(42),
},
{
label: 'fractional',
pledgedSrcSize: 1.9,
input: Buffer.alloc(1),
},
{
label: 'NaN',
pledgedSrcSize: NaN,
input: Buffer.alloc(0),
},
{
label: 'Infinity',
pledgedSrcSize: Infinity,
input: Buffer.alloc(0),
},
{
label: 'unsafe integers',
pledgedSrcSize: Number.MAX_SAFE_INTEGER + 1,
input: Buffer.alloc(0),
},
];
for (const { label, pledgedSrcSize, input } of cases) {
try {
zlib.zstdCompressSync(input, { pledgedSrcSize });
console.log(`${label}: accepted`);
} catch (error) {
console.log(`${label}: ${error.code}`);
}
}
How often does it reproduce? Is there a required condition?
Every time
What is the expected behavior? Why is that the expected behavior?
pledgedSrcSize represents the expected exact byte length of the uncompressed input. However, the current Zstd binding does not strictly validate this option.Non-number values are silently treated as if the option was omitted, while IntegerValue() implicitly converts values such as fractional numbers and NaN.
What do you see instead?
string: accepted
null: accepted
fraction: accepted
NaN: accepted
Infinity: ZSTD_error_srcSize_wrong
unsafe integer: ZSTD_error_srcSize_wrong
Additional information
Only undefined or a non-negative safe integer should be accepted.
-
Non-number values should throw ERR_INVALID_ARG_TYPE.
-
NaN, Infinity, fractional numbers, negative numbers, and unsafe integers should throw ERR_OUT_OF_RANGE.
-
Invalid options should be rejected during argument validation rather than producing a later ZSTD_error_srcSize_wrong.
Values above Number.MAX_SAFE_INTEGER should not be accepted because JavaScript cannot represent every integer in that range precisely, while the pledged size represents an exact byte count.
Version
latest main branch
Platform
Subsystem
zlib
What steps will reproduce the bug?
How often does it reproduce? Is there a required condition?
Every time
What is the expected behavior? Why is that the expected behavior?
pledgedSrcSize represents the expected exact byte length of the uncompressed input. However, the current Zstd binding does not strictly validate this option.Non-number values are silently treated as if the option was omitted, while IntegerValue() implicitly converts values such as fractional numbers and NaN.
What do you see instead?
string: accepted
null: accepted
fraction: accepted
NaN: accepted
Infinity: ZSTD_error_srcSize_wrong
unsafe integer: ZSTD_error_srcSize_wrong
Additional information
Only undefined or a non-negative safe integer should be accepted.
Non-number values should throw ERR_INVALID_ARG_TYPE.
NaN, Infinity, fractional numbers, negative numbers, and unsafe integers should throw ERR_OUT_OF_RANGE.
Invalid options should be rejected during argument validation rather than producing a later ZSTD_error_srcSize_wrong.
Values above Number.MAX_SAFE_INTEGER should not be accepted because JavaScript cannot represent every integer in that range precisely, while the pledged size represents an exact byte count.