-
-
Notifications
You must be signed in to change notification settings - Fork 33.5k
[v8.x] buffer: zero-fill buffer allocated with invalid content #17467
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 all commits
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 |
---|---|---|
|
@@ -238,7 +238,9 @@ Buffer.alloc = function(size, fill, encoding) { | |
// be interpreted as a start offset. | ||
if (typeof encoding !== 'string') | ||
encoding = undefined; | ||
return createUnsafeBuffer(size).fill(fill, encoding); | ||
const ret = createUnsafeBuffer(size); | ||
if (fill_(ret, fill, encoding) > 0) | ||
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. Maybe leave a comment here?
|
||
return ret; | ||
} | ||
return new FastBuffer(size); | ||
}; | ||
|
@@ -796,15 +798,20 @@ Buffer.prototype.includes = function includes(val, byteOffset, encoding) { | |
// buffer.fill(buffer[, offset[, end]]) | ||
// buffer.fill(string[, offset[, end]][, encoding]) | ||
Buffer.prototype.fill = function fill(val, start, end, encoding) { | ||
fill_(this, val, start, end, encoding); | ||
return this; | ||
}; | ||
|
||
function fill_(buf, val, start, end, encoding) { | ||
// Handle string cases: | ||
if (typeof val === 'string') { | ||
if (typeof start === 'string') { | ||
encoding = start; | ||
start = 0; | ||
end = this.length; | ||
end = buf.length; | ||
} else if (typeof end === 'string') { | ||
encoding = end; | ||
end = this.length; | ||
end = buf.length; | ||
} | ||
|
||
if (encoding !== undefined && typeof encoding !== 'string') { | ||
|
@@ -832,19 +839,17 @@ Buffer.prototype.fill = function fill(val, start, end, encoding) { | |
} | ||
|
||
// Invalid ranges are not set to a default, so can range check early. | ||
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. Should it say "so one can range check early."? 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. Or maybe
|
||
if (start < 0 || end > this.length) | ||
if (start < 0 || end > buf.length) | ||
throw new RangeError('Out of range index'); | ||
|
||
if (end <= start) | ||
return this; | ||
return 0; | ||
|
||
start = start >>> 0; | ||
end = end === undefined ? this.length : end >>> 0; | ||
end = end === undefined ? buf.length : end >>> 0; | ||
|
||
binding.fill(this, val, start, end, encoding); | ||
|
||
return this; | ||
}; | ||
return binding.fill(buf, val, start, end, encoding); | ||
} | ||
|
||
|
||
Buffer.prototype.write = function(string, offset, length, encoding) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ prefix sequential | |
test-inspector-async-call-stack : PASS, FLAKY | ||
test-inspector-bindings : PASS, FLAKY | ||
test-inspector-debug-end : PASS, FLAKY | ||
test-inspector-async-hook-setup-at-signal: PASS, FLAKY | ||
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. Hm, is this related to the change here? 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. No, this snuck its way in here because The commits should still apply cleanly; I can rebase this PR if @gibfahn likes. |
||
|
||
[$system==linux] | ||
|
||
|
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm wondering if we should use something like
bbzz
here. Witha
it's unclear if no filling is performed or if the string was truncated. Also, should the last example have a// Prints: ...
?