-
Notifications
You must be signed in to change notification settings - Fork 30k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
If an object's prototype is munged it's possible to bypass the instanceof check and cause the application to abort. Instead now use HasInstance() to verify that the object is a Buffer, and throw if not. This check will not work for JS only methods. So while the application won't abort, it also won't throw. In order to properly throw in all cases with toString() the JS optimization of checking that length is zero has been removed. In its place the native methods will now return early if a zero length string is detected. Ref: #1486 Ref: #1922 Fixes: #1485 PR-URL: #2012 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
- Loading branch information
1 parent
856c11f
commit 1cd9eeb
Showing
3 changed files
with
88 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
const assert = require('assert'); | ||
const Buffer = require('buffer').Buffer; | ||
const Bp = Buffer.prototype; | ||
|
||
function FakeBuffer() { } | ||
FakeBuffer.__proto__ = Buffer; | ||
FakeBuffer.prototype.__proto__ = Buffer.prototype; | ||
|
||
const fb = new FakeBuffer(); | ||
|
||
assert.throws(function() { | ||
new Buffer(fb); | ||
}, TypeError); | ||
|
||
assert.throws(function() { | ||
+Buffer.prototype; | ||
}, TypeError); | ||
|
||
assert.throws(function() { | ||
Buffer.compare(fb, new Buffer(0)); | ||
}, TypeError); | ||
|
||
assert.throws(function() { | ||
fb.write('foo'); | ||
}, TypeError); | ||
|
||
assert.throws(function() { | ||
Buffer.concat([fb, fb]); | ||
}, TypeError); | ||
|
||
assert.throws(function() { | ||
fb.toString(); | ||
}, TypeError); | ||
|
||
assert.throws(function() { | ||
fb.equals(new Buffer(0)); | ||
}, TypeError); | ||
|
||
assert.throws(function() { | ||
fb.indexOf(5); | ||
}, TypeError); | ||
|
||
assert.throws(function() { | ||
fb.readFloatLE(0); | ||
}, TypeError); | ||
|
||
assert.throws(function() { | ||
fb.writeFloatLE(0); | ||
}, TypeError); | ||
|
||
assert.throws(function() { | ||
fb.fill(0); | ||
}, TypeError); |