0
0
mirror of https://github.com/nodejs/node.git synced 2024-12-01 16:10:02 +01:00
nodejs/test/parallel/test-fs-readdir-stack-overflow.js
Joyee Cheung c5c9515c1b
fs: fix stack overflow in fs.readdirSync
Previously, fs.readdirSync calls the function returned by
env->push_values_to_array_function() in batch and check the returned
Maybe right away in C++, which can lead to assertions if the call stack
already reaches the maximum size. This patch fixes that by returning
early the call fails so the stack overflow error will be properly
thrown into JS land.

PR-URL: https://github.com/nodejs/node/pull/18647
Fixes: https://github.com/nodejs/node/issues/18645
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: James M Snell <jasnell@gmail.com>
2018-02-10 15:58:45 +01:00

19 lines
261 B
JavaScript

'use strict';
const common = require('../common');
const fs = require('fs');
function recurse() {
fs.readdirSync('.');
recurse();
}
common.expectsError(
() => recurse(),
{
type: RangeError,
message: 'Maximum call stack size exceeded'
}
);