0
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-02-08 07:16:56 -05:00

fix(ext/node): scrypt panic when log_n > 64 (#27816)

Throws an error instead of panic. Ref
https://github.com/denoland/deno/issues/27716
This commit is contained in:
Divy Srivastava 2025-01-27 09:12:51 +05:30 committed by GitHub
parent 8ccc05e503
commit 1efc77331c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 24 additions and 18 deletions

View file

@ -571,7 +571,7 @@ fn scrypt(
parallelization,
keylen as usize,
)
.unwrap();
.map_err(|_| JsErrorBox::generic("scrypt params construction failed"))?;
// Call into scrypt
let res = scrypt::scrypt(&password, &salt, &params, output_buffer);

View file

@ -107,23 +107,19 @@ export function scrypt(
throw new Error("exceeds max memory");
}
try {
op_node_scrypt_async(
password,
salt,
keylen,
Math.log2(N),
r,
p,
maxmem,
).then(
(buf: Uint8Array) => {
cb(null, Buffer.from(buf.buffer));
},
);
} catch (err: unknown) {
return cb(err);
}
op_node_scrypt_async(
password,
salt,
keylen,
Math.log2(N),
r,
p,
maxmem,
).then(
(buf: Uint8Array) => {
cb(null, Buffer.from(buf.buffer));
},
).catch((err: unknown) => cb(err));
}
export default {

View file

@ -188,3 +188,13 @@ Deno.test("scryptSync with options works correctly", () => {
]),
);
});
Deno.test("log_n > 64 doesn't panic", async () => {
const { promise, resolve } = Promise.withResolvers<void>();
scrypt("password", "salt", 128, () => {
resolve();
});
await promise;
});