fix(ext/node): align input validation of Buffer.compare (#29275)
Some checks are pending
ci / test debug windows-x86_64 (push) Blocked by required conditions
ci / test release macos-x86_64 (push) Blocked by required conditions
ci / test release windows-x86_64 (push) Blocked by required conditions
ci / test debug macos-x86_64 (push) Blocked by required conditions
ci / pre-build (push) Waiting to run
ci / test debug linux-aarch64 (push) Blocked by required conditions
ci / test release linux-aarch64 (push) Blocked by required conditions
ci / test debug macos-aarch64 (push) Blocked by required conditions
ci / test release macos-aarch64 (push) Blocked by required conditions
ci / bench release linux-x86_64 (push) Blocked by required conditions
ci / lint debug linux-x86_64 (push) Blocked by required conditions
ci / lint debug macos-x86_64 (push) Blocked by required conditions
ci / lint debug windows-x86_64 (push) Blocked by required conditions
ci / test debug linux-x86_64 (push) Blocked by required conditions
ci / test release linux-x86_64 (push) Blocked by required conditions
ci / build wasm32 (push) Blocked by required conditions
ci / publish canary (push) Blocked by required conditions

This commit is contained in:
Yoshiya Hinosawa 2025-05-13 17:14:19 +09:00 committed by GitHub
parent acd0c94b46
commit 1022decc79
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 62 additions and 19 deletions

View file

@ -382,25 +382,14 @@ const BufferIsBuffer = Buffer.isBuffer = function isBuffer(b) {
};
const BufferCompare = Buffer.compare = function compare(a, b) {
if (isUint8Array(a)) {
a = BufferFrom(
a,
TypedArrayPrototypeGetByteOffset(a),
TypedArrayPrototypeGetByteLength(a),
);
if (!isUint8Array(a)) {
throw new codes.ERR_INVALID_ARG_TYPE("buf1", ["Buffer", "Uint8Array"], a);
}
if (isUint8Array(b)) {
b = BufferFrom(
b,
TypedArrayPrototypeGetByteOffset(b),
TypedArrayPrototypeGetByteLength(b),
);
}
if (!BufferIsBuffer(a) || !BufferIsBuffer(b)) {
throw new TypeError(
'The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array',
);
if (!isUint8Array(b)) {
throw new ERR_INVALID_ARG_TYPE("buf2", ["Buffer", "Uint8Array"], b);
}
if (a === b) {
return 0;
}