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

.parent and .offset of Buffer and SlowBuffer .prototype throw an exception when accessed #3297

Closed
wraithan opened this issue Oct 9, 2015 · 1 comment
Labels
buffer Issues and PRs related to the buffer subsystem.

Comments

@wraithan
Copy link

wraithan commented Oct 9, 2015

I was writing a tool to scrape the APIs of everything and stumbled across these in the buffer module.

Repro:

Run the following JS on any version of node/io.js from 3.0.0 until 4.1.2 (current as of time of writing)

var buffer = require('buffer')
buffer.Buffer.prototype.parent
buffer.Buffer.prototype.offset
buffer.SlowBuffer.prototype.parent
buffer.SlowBuffer.prototype.offset

Example output:

buffer.js:311
    if (this.byteLength === 0 ||
            ^

TypeError: Method Uint8Array.byteLength called on incompatible receiver [object Object]
    at Buffer.get byteLength (native)
    at Buffer.Object.defineProperty.get [as parent] (buffer.js:311:13)
    at Object.<anonymous> (/Users/wmcdonald/devel/newrelic/api-scraper/bad-buffer.js:2:24)
    at Module._compile (module.js:434:26)
    at Object.Module._extensions..js (module.js:452:10)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)
    at Function.Module.runMain (module.js:475:10)
    at startup (node.js:118:18)
    at node.js:952:3

CCing @trevnorris since he asked me to.

@wraithan wraithan changed the title .parent and .offset of Buffer and SlowBuffer .prototype throw an exception when accessed: .parent and .offset of Buffer and SlowBuffer .prototype throw an exception when accessed Oct 9, 2015
@mscdex mscdex added the buffer Issues and PRs related to the buffer subsystem. label Oct 9, 2015
trevnorris added a commit to trevnorris/node that referenced this issue Oct 9, 2015
Accessing prototype properties directly on a typed array will throw. So
do an extra check in Buffer's own getters to verify it is being called
on an instance.

Fixes: nodejs#3297
@trevnorris
Copy link
Contributor

Posted fix, running CI.

trevnorris added a commit that referenced this issue Oct 10, 2015
Accessing prototype properties directly on a typed array will throw. So
do an extra check in Buffer's own getters to verify it is being called
on an instance.

Fixes: #3297
PR-URL: #3302
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
buffer Issues and PRs related to the buffer subsystem.
Projects
None yet
Development

No branches or pull requests

3 participants