diff options
author | Ruben Bridgewater <ruben@bridgewater.de> | 2018-05-16 18:10:08 +0200 |
---|---|---|
committer | Ruben Bridgewater <ruben@bridgewater.de> | 2018-09-13 10:49:04 +0200 |
commit | eb61127c48ba59e52d7cea293ad80fa54000939c (patch) | |
tree | bac34ae84a86c310684a0148a42b6a8d71047759 /test/parallel/test-util-inspect-long-running.js | |
parent | 1cee08536794b6d7bc8d3b9ace2b494c74985f7d (diff) | |
download | android-node-v8-eb61127c48ba59e52d7cea293ad80fa54000939c.tar.gz android-node-v8-eb61127c48ba59e52d7cea293ad80fa54000939c.tar.bz2 android-node-v8-eb61127c48ba59e52d7cea293ad80fa54000939c.zip |
util: limit inspection output size to 128 MB
The maximum hard limit that `util.inspect()` could theoretically handle
is the maximum string size. That is ~2 ** 28 on 32 bit systems and
~2 ** 30 on 64 bit systems.
Due to the recursive algorithm a complex object could easily exceed
that limit without throwing an error right away and therefore
crashing the application by exceeding the heap limit.
`util.inspect()` is fast enough to compute 128 MB of data below one
second on an Intel(R) Core(TM) i7-5600U CPU. This hard limit allows
to inspect arbitrary big objects from now on without crashing the
application or blocking the event loop significantly.
PR-URL: https://github.com/nodejs/node/pull/22756
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: John-David Dalton <john.david.dalton@gmail.com>
Diffstat (limited to 'test/parallel/test-util-inspect-long-running.js')
-rw-r--r-- | test/parallel/test-util-inspect-long-running.js | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/test/parallel/test-util-inspect-long-running.js b/test/parallel/test-util-inspect-long-running.js new file mode 100644 index 0000000000..167f72ba64 --- /dev/null +++ b/test/parallel/test-util-inspect-long-running.js @@ -0,0 +1,20 @@ +'use strict'; + +require('../common'); + +// Test that huge objects don't crash due to exceeding the maximum heap size. + +const util = require('util'); + +// Create a difficult to stringify object. Without the artificial limitation +// this would crash or throw an maximum string size error. +let last = {}; +const obj = last; + +for (let i = 0; i < 1000; i++) { + last.next = { circular: obj, last, obj: { a: 1, b: 2, c: true } }; + last = last.next; + obj[i] = last; +} + +util.inspect(obj, { depth: Infinity }); |