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:
parent
8ccc05e503
commit
1efc77331c
3 changed files with 24 additions and 18 deletions
|
@ -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, ¶ms, output_buffer);
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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;
|
||||
});
|
||||
|
|
Loading…
Add table
Reference in a new issue