Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 6 commits into from
Jan 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ext/node/ops/crypto/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
30 changes: 13 additions & 17 deletions ext/node/polyfills/internal/crypto/scrypt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
10 changes: 10 additions & 0 deletions tests/unit_node/crypto/crypto_scrypt_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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