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

buffer.toString fails for buffers larger than 192MB #4266

Closed
skilledDeveloper opened this issue Dec 14, 2015 · 17 comments
Closed

buffer.toString fails for buffers larger than 192MB #4266

skilledDeveloper opened this issue Dec 14, 2015 · 17 comments
Labels
buffer Issues and PRs related to the buffer subsystem.

Comments

@skilledDeveloper
Copy link

buffer.toString with base64 encoding fails for any buffer larger than or equal to 201326581 bytes (~192 MB).

See the following piece of code:

var buf1 = new Buffer(201326580),  //biggest buffer that works
    buf2 = new Buffer(201326581);  //~192 MB
buf1.toString('base64'); //works
buf2.toString('base64'); //fails!

For older node versions (like v0.12.2) this cause the process to crash with this error:

#
# Fatal error in d:\jenkins\workspace\nodejs-msi-julien\d8c2e2bb\deps\v8\src/handles.h, line 48
# CHECK(location_ != NULL) failed
#
Segmentation fault      

For newer versions (like v5.2.0), it gives the following error:

buffer.js:401
    throw new Error('toString failed');
    ^
@mscdex mscdex added the buffer Issues and PRs related to the buffer subsystem. label Dec 14, 2015
@ChALkeR
Copy link
Member

ChALkeR commented Dec 14, 2015

Probably a dupe of #3175

@bnoordhuis
Copy link
Member

Slightly more representative tests:

Buffer(268435440).toString('binary');  // ok
Buffer(268435441).toString('binary');  // crashes in v0.12

Nominally a V8 bug due to the use of .ToHandleChecked() in deps/v8/src/api.cc. We could work around it by checking that length < 268435441 before calling v8::String::NewExternal() in src/string_bytes.cc.

I'm not going to work on it but if someone wants to pick it up, I'll review the patches.

@Fishrock123 Fishrock123 added the good first issue Issues that are suitable for first-time contributors. label Dec 15, 2015
@skilledDeveloper
Copy link
Author

@bnoordhuis
I'll work on it.

skilledDeveloper added a commit to skilledDeveloper/node that referenced this issue Dec 15, 2015
workaround for possible V8 bug (due to the use of .ToHandleChecked() in deps/v8/src/api.cc)
@bnoordhuis please review
@silverwind
Copy link
Contributor

Is v4 also affected?

@skilledDeveloper
Copy link
Author

Yes. but it doesn't crash the process.

@RohanGada
Copy link

Unable to read a 40MB xlsx due to this.
mongod 3.0.6
Node 0.12.7

@trevnorris
Copy link
Contributor

@RohanGada Mind opening another issue with test case we can look at? Your issue will probably go unnoticed within an already closed issue.

EDIT: This isn't a closed issue yet. Don't know why I thought so.

@RohanGada
Copy link

Okay

@lprimeroo
Copy link

Is this fixed ?

@silverwind
Copy link
Contributor

#4394 has yet to land.

@ChALkeR ChALkeR added the v0.12 label Jan 12, 2016
@Fishrock123 Fishrock123 removed the good first issue Issues that are suitable for first-time contributors. label May 5, 2016
@wmbutler
Copy link

Curious to know if there's been any progress on this yet? I'm running v5.6.0 and still seeing this behavior.

@trevnorris
Copy link
Contributor

Best I can figure this is a v8 bug. Unfortunately my v8 foo isn't good enough to track this down. /cc @indutny want to track down a v8 crash? :)

@wmbutler
Copy link

I had to bypass node and use bash with jq to parse large base64 objects through bash.

@davidrapin
Copy link

This issue is a duplicate of #3175

@skilledDeveloper
Copy link
Author

@davidrapin It's not duplicate.
This is about an unhanded exception which breaks the process.

@davidrapin
Copy link

davidrapin commented Oct 6, 2016

Ok got it, just found out what the v0.12 tag meant ;)

n-riesco added a commit to n-riesco/jmp that referenced this issue Nov 4, 2016
* Workaround for Buffer.toString failure caused by exceeding the maximum
  supported length in V8.

* See issue nodejs/node#4266
  and PR nodejs/node#4394

Fixes #22
@jasnell
Copy link
Member

jasnell commented Dec 29, 2016

Closing this given that support for v0.12 is coming to a close in two days and there will not be any further updates to the v0.12 branch.

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