Skip to content

Commit 58fe440

Browse files
committed
src: ignore SIGXFSZ, don't terminate (ulimit -f)
Ignore SIGXFSZ signals so that exceeding RLIMIT_FSIZE makes the offending system call fail with EFBIG instead of terminating the process. PR-URL: #27798 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Richard Lau <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]>
1 parent ca8e33a commit 58fe440

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

src/node.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,7 @@ inline void PlatformInit() {
517517
for (unsigned nr = 1; nr < kMaxSignal; nr += 1) {
518518
if (nr == SIGKILL || nr == SIGSTOP)
519519
continue;
520-
act.sa_handler = (nr == SIGPIPE) ? SIG_IGN : SIG_DFL;
520+
act.sa_handler = (nr == SIGPIPE || nr == SIGXFSZ) ? SIG_IGN : SIG_DFL;
521521
CHECK_EQ(0, sigaction(nr, &act, nullptr));
522522
}
523523
#endif // !NODE_SHARED_MODE
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Check that exceeding RLIMIT_FSIZE fails with EFBIG
2+
// rather than terminating the process with SIGXFSZ.
3+
'use strict';
4+
const common = require('../common');
5+
const tmpdir = require('../common/tmpdir');
6+
7+
const assert = require('assert');
8+
const child_process = require('child_process');
9+
const fs = require('fs');
10+
const path = require('path');
11+
12+
if (common.isWindows)
13+
common.skip('no RLIMIT_FSIZE on Windows');
14+
15+
if (process.config.variables.node_shared)
16+
common.skip('SIGXFSZ signal handler not installed in shared library mode');
17+
18+
if (process.argv[2] === 'child') {
19+
const filename = path.join(tmpdir.path, 'efbig.txt');
20+
tmpdir.refresh();
21+
fs.writeFileSync(filename, '.'.repeat(1 << 16)); // Exceeds RLIMIT_FSIZE.
22+
} else {
23+
const cmd = `ulimit -f 1 && '${process.execPath}' '${__filename}' child`;
24+
const result = child_process.spawnSync('/bin/sh', ['-c', cmd]);
25+
const haystack = result.stderr.toString();
26+
const needle = 'Error: EFBIG: file too large, write';
27+
const ok = haystack.includes(needle);
28+
if (!ok) console.error(haystack);
29+
assert(ok);
30+
assert.strictEqual(result.status, 1);
31+
assert.strictEqual(result.stdout.toString(), '');
32+
}

0 commit comments

Comments
 (0)