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

Fatal Error (Abort) creating string larger than 268435440 bytes #1374

Closed
juliangruber opened this issue Apr 8, 2015 · 16 comments
Closed

Fatal Error (Abort) creating string larger than 268435440 bytes #1374

juliangruber opened this issue Apr 8, 2015 · 16 comments
Labels
buffer Issues and PRs related to the buffer subsystem. v8 engine Issues and PRs related to the V8 dependency.
Milestone

Comments

@juliangruber
Copy link
Member

Given this script:

var kMaxLength = process.binding('smalloc').kMaxLength;
console.log(kMaxLength, 'kMaxLength');

var len = 268435440;
var blob = new Buffer(len).toString('utf8');
console.log(len, 'ok');

len = 268435441;
blob = new Buffer(len).toString('utf8');
console.log(len, 'ok');

The output should be:

1073741823 'kMaxLength'
268435440 'ok'
268435441 'ok'

But it actually is:

1073741823 'kMaxLength'
268435440 'ok'


#
# Fatal error in ../deps/v8/src/handles.h, line 48
# CHECK(location_ != NULL) failed
#

==== C stack trace ===============================

 1: ??
 2: ??
 3: ??
 4: ??
 5: ??
 6: ??
 7: ??
 8: ??
 9: ??
Illegal instruction: 4
@juliangruber
Copy link
Member Author

this is ~256mb

@petkaantonov
Copy link
Contributor

@trevnorris @chrisdickinson and I are already working on this FWIW

@petkaantonov
Copy link
Contributor

If your file is just using ascii, you can work around this currently by specifying 'ascii' as encoding

@Fishrock123 Fishrock123 added smalloc buffer Issues and PRs related to the buffer subsystem. labels Apr 8, 2015
@Fishrock123
Copy link
Contributor

I feel like this has already been reported, but I can't find the issue..

@juliangruber
Copy link
Member Author

here is a stacktrace i get on linux:

==== C stack trace ===============================

 1: V8_Fatal
 2: v8::String::NewFromUtf8(v8::Isolate*, char const*, v8::String::NewStringType, int)
 3: node::StringBytes::Encode(v8::Isolate*, char const*, unsigned long, node::encoding)
 4: node::Buffer::Utf8Slice(v8::FunctionCallbackInfo<v8::Value> const&)
 5: v8::internal::FunctionCallbackArguments::Call(void (*)(v8::FunctionCallbackInfo<v8::Value> const&))
 6: ??
 7: ??
Illegal instruction (core dumped)

@juliangruber juliangruber changed the title Fatal Error creating buffer larger than 268435440 bytes Fatal Error creating string larger than 268435440 bytes Apr 8, 2015
@juliangruber
Copy link
Member Author

updated the title, the issue is obviously the .toString()

@Fishrock123
Copy link
Contributor

@juliangruber ah. Is this related to #649?

@Fishrock123 Fishrock123 added v8 engine Issues and PRs related to the V8 dependency. and removed smalloc labels Apr 8, 2015
@petkaantonov
Copy link
Contributor

@Fishrock123 yes, there is even a same issue reported deep in the comments.

It's not a v8 issue, while v8 does have a smallish limit for strings allocated in the js-heap (the 268mb or so), it is our fault for trying to allocate the string in js-heap in the first place.

@brendanashworth
Copy link
Contributor

This doesn't seem to be an issue with the new Buffer rewrite / removal of smalloc:

brendanashworth in ~ $ node -v
v2.1.0
brendanashworth in ~ $ node test
1073741823 'kMaxLength'
268435440 'ok'
FATAL ERROR: invalid array length Allocation failed - process out of memory
Abort trap: 6
brendanashworth in ~ $ node -v
v3.0.0
brendanashworth in ~ $ node test
268435440 'ok'
268435441 'ok'

Closing this for now, feel free to reopen if I'm wrong! :)

@trevnorris
Copy link
Contributor

This isn't an issue of the smalloc change, but it is an issue. The fix is just about to be landed in #2402

@trevnorris trevnorris reopened this Sep 2, 2015
trevnorris pushed a commit that referenced this issue Sep 2, 2015
v8 will silently return an empty handle
which doesn't delete our data if string length is
above String::kMaxLength

Fixes: #1374
PR-URL: #2402
Reviewed-By: trevnorris - Trevor Norris <trev.norris@gmail.com>
Reviewed-By: indutny - Fedor Indutny <fedor.indutny@gmail.com>
Reviewed-By: bnoordhuis - Ben Noordhuis <info@bnoordhuis.nl>
@trevnorris
Copy link
Contributor

Fixed by 617ee32.

@trevnorris trevnorris added this to the 4.0.0 milestone Sep 3, 2015
@trevnorris
Copy link
Contributor

@rvagg Adding this to the v4.0.0 milestone because it's a patch that prevents a possible segfault.

Fishrock123 pushed a commit that referenced this issue Sep 3, 2015
v8 will silently return an empty handle
which doesn't delete our data if string length is
above String::kMaxLength

Fixes: #1374
PR-URL: #2402
Reviewed-By: trevnorris - Trevor Norris <trev.norris@gmail.com>
Reviewed-By: indutny - Fedor Indutny <fedor.indutny@gmail.com>
Reviewed-By: bnoordhuis - Ben Noordhuis <info@bnoordhuis.nl>
Fishrock123 pushed a commit to Fishrock123/node that referenced this issue Sep 3, 2015
v8 will silently return an empty handle
which doesn't delete our data if string length is
above String::kMaxLength

Fixes: nodejs#1374
PR-URL: nodejs#2402
Reviewed-By: trevnorris - Trevor Norris <trev.norris@gmail.com>
Reviewed-By: indutny - Fedor Indutny <fedor.indutny@gmail.com>
Reviewed-By: bnoordhuis - Ben Noordhuis <info@bnoordhuis.nl>
rvagg pushed a commit that referenced this issue Sep 6, 2015
v8 will silently return an empty handle
which doesn't delete our data if string length is
above String::kMaxLength

Fixes: #1374
PR-URL: #2402
Reviewed-By: trevnorris - Trevor Norris <trev.norris@gmail.com>
Reviewed-By: indutny - Fedor Indutny <fedor.indutny@gmail.com>
Reviewed-By: bnoordhuis - Ben Noordhuis <info@bnoordhuis.nl>

Amended by @rvagg to change author date from
  "1970-08-16 16:09:02 +0200"
to
  "2015-08-16 16:09:02 +0200"
as per discussion @ #2713
rvagg pushed a commit that referenced this issue Sep 6, 2015
v8 will silently return an empty handle
which doesn't delete our data if string length is
above String::kMaxLength

Fixes: #1374
PR-URL: #2402
Reviewed-By: trevnorris - Trevor Norris <trev.norris@gmail.com>
Reviewed-By: indutny - Fedor Indutny <fedor.indutny@gmail.com>
Reviewed-By: bnoordhuis - Ben Noordhuis <info@bnoordhuis.nl>

Amended by @rvagg to change author date from
  "1970-08-16 16:09:02 +0200"
to
  "2015-08-16 16:09:02 +0200"
as per discussion @ #2713
rvagg pushed a commit that referenced this issue Sep 6, 2015
v8 will silently return an empty handle
which doesn't delete our data if string length is
above String::kMaxLength

Fixes: #1374
PR-URL: #2402
Reviewed-By: trevnorris - Trevor Norris <trev.norris@gmail.com>
Reviewed-By: indutny - Fedor Indutny <fedor.indutny@gmail.com>
Reviewed-By: bnoordhuis - Ben Noordhuis <info@bnoordhuis.nl>

Amended by @rvagg to change author date from
  "1970-08-16 16:09:02 +0200"
to
  "2015-08-16 16:09:02 +0200"
as per discussion @ #2713
rvagg pushed a commit that referenced this issue Sep 6, 2015
v8 will silently return an empty handle
which doesn't delete our data if string length is
above String::kMaxLength

Fixes: #1374
PR-URL: #2402
Reviewed-By: trevnorris - Trevor Norris <trev.norris@gmail.com>
Reviewed-By: indutny - Fedor Indutny <fedor.indutny@gmail.com>
Reviewed-By: bnoordhuis - Ben Noordhuis <info@bnoordhuis.nl>

Amended by @rvagg to change author date from
  "1970-08-16 16:09:02 +0200"
to
  "2015-08-16 16:09:02 +0200"
as per discussion @ #2713
@mhart
Copy link
Contributor

mhart commented Oct 4, 2015

I believe this should be reopened. Output under v4.1.1 is:

268435440 'ok'
buffer.js:378
    throw new Error('toString failed');
    ^

Error: toString failed
    at Buffer.toString (buffer.js:378:11)
    at Object.<anonymous> (/Users/michael/github/rss/data/test.js:6: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:117:18)
    at node.js:951:3

@bnoordhuis
Copy link
Member

@mhart This issue is about node aborting on large strings. It no longer does, it throws a catchable exception.

@mhart
Copy link
Contributor

mhart commented Oct 4, 2015

OK, I was going by the expected output in the issue description.

@Fishrock123 Fishrock123 changed the title Fatal Error creating string larger than 268435440 bytes Fatal Error (Abort) creating string larger than 268435440 bytes Oct 4, 2015
@arjunkori
Copy link

i am getting the same issue ,

  buffer.js:378
    throw new Error('toString failed');^
Error: toString failed
    at Buffer.toString (buffer.js:378:11)

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. v8 engine Issues and PRs related to the V8 dependency.
Projects
None yet
Development

No branches or pull requests

8 participants