-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Hardening: input validation and bounds checking across 12 subsystems (round 8) #31559
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
Changes from 20 commits
74a3b43
fd804a3
0c327b7
bc04040
0cda3fd
9f11fe1
2a18007
c313159
5daffe4
9786c09
860577b
97adcbf
f5409ee
8db23c4
6c1ffb2
99b6a0a
c545eb6
e79d0e0
342d39d
ae77ef3
7bee3c7
d342992
07eabcc
4e2b03a
f082d95
002e8f0
077ee84
7a35ffa
bd18e22
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3995,11 +3995,19 @@ pub mod args { | |
| }; | ||
|
|
||
| // length |= 0; | ||
| let length_float: f64 = if let Some(arg) = arguments.next_eat() { | ||
| let length_value = arguments.next_eat(); | ||
| let length_float: f64 = if let Some(arg) = length_value { | ||
| arg.to_number(ctx)? | ||
| } else { | ||
| 0.0 | ||
| }; | ||
| let buffer = if length_value.is_some_and(|arg| !arg.is_number()) { | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do not make it slower. One pass. Not two.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Reordered to a single pass — the re-fetch is gone. The buffer pointer/length is now captured exactly once, immediately after the offset/length arguments are processed (length's ToNumber is the only step there that can re-enter JS), so nothing captured before that point is used after it. The all-numbers fast path does exactly the same operations as before this change set: fd, offset validation, length ToNumber, then one Buffer::from_js — no added conversions or branches, just a different order. The readSync detach test still fails on the released build and passes here, test-fs-read* parallel tests pass, and a readSync loop microbench is at parity with main. |
||
| Buffer::from_js(ctx, buffer_value).ok_or_else(|| { | ||
| ctx.throw_invalid_argument_type_value(b"buffer", b"TypedArray", buffer_value) | ||
| })? | ||
| } else { | ||
| buffer | ||
| }; | ||
|
|
||
| // if (length === 0) { | ||
| // return process.nextTick(function tick() { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1220,6 +1220,12 @@ impl PathLikeExt for PathLike { | |
| Valid::path_buffer(&buffer, ctx)?; | ||
| Valid::path_null_bytes(buffer.slice(), ctx)?; | ||
|
|
||
| let buffer = if arguments.will_be_async { | ||
| Buffer::from_js_pinned(ctx, arg).unwrap_or(buffer) | ||
| } else { | ||
| buffer | ||
| }; | ||
|
|
||
| arguments.protect_eat(); | ||
| Ok(Some(Self::Buffer(buffer))) | ||
| } | ||
|
|
@@ -1229,6 +1235,12 @@ impl PathLikeExt for PathLike { | |
| Valid::path_buffer(&buffer, ctx)?; | ||
| Valid::path_null_bytes(buffer.slice(), ctx)?; | ||
|
|
||
| let buffer = if arguments.will_be_async { | ||
| Buffer::from_js_pinned(ctx, arg).unwrap_or(buffer) | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This makes it slower. One pass. Not 2.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Restructured to one pass. When the call will be async, the single conversion is now |
||
| } else { | ||
| buffer | ||
| }; | ||
|
|
||
| arguments.protect_eat(); | ||
| Ok(Some(Self::Buffer(buffer))) | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.