buffer: convert range to numbers before validation#9158
buffer: convert range to numbers before validation#9158cjihrig wants to merge 1 commit intonodejs:masterfrom
Conversation
Prior to this commit, a carefully crafted object with a Symbol.toPrimitive could bypass range validation. This commit converts the range values to numbers before performing any validation.
|
LGTM. Looking at this made me wonder though about I'm leaning to rounding before the range check, because the docs say, |
|
@fhinkel, I originally thought to completely process the input before doing any checks. However, that would have been a breaking change. This seems to be more backwards compatible. I wouldn't be opposed to doing a follow up breaking change for v7 or v8. |
|
Sounds good! |
|
While you're at it, may I suggest adding a fix to the binding code. The issue is here: size_t start = args[2]->Uint32Value();
size_t end = args[3]->Uint32Value();I think it's worth checking the types of const buff = Buffer.alloc(1);
const start = {
[Symbol.toPrimitive](hint) {
throw "hard crash";
}
};
process.binding('buffer').fill(buff, start, 1); |
|
@deian allowing it to crash in a way that a |
|
@trevnorris that snippet will segfault (or maybe that's what you meant?) |
Checklist
make -j8 test(UNIX), orvcbuild test nosign(Windows) passesAffected core subsystem(s)
buffer
Description of change
Prior to this commit, a carefully crafted object with a
Symbol.toPrimitivecould bypass range validation. This commit converts the range values to numbers before performing any validation.Note, this commit converts
startandendto a number before later converting to unsigned ints. This is a bit of duplicate work, but maintains backwards compatibility.Fixes: #9149