1'use strict'; 2 3// Tests that passing a negative offset does not crash the process 4 5const common = require('../common'); 6 7const { 8 join, 9} = require('path'); 10 11const { 12 closeSync, 13 open, 14 write, 15 writeSync, 16} = require('fs'); 17 18const assert = require('assert'); 19 20const tmpdir = require('../common/tmpdir'); 21tmpdir.refresh(); 22 23const filename = join(tmpdir.path, 'test.txt'); 24 25open(filename, 'w+', common.mustSucceed((fd) => { 26 assert.throws(() => { 27 write(fd, Buffer.alloc(0), -1, common.mustNotCall()); 28 }, { 29 code: 'ERR_OUT_OF_RANGE', 30 }); 31 assert.throws(() => { 32 writeSync(fd, Buffer.alloc(0), -1); 33 }, { 34 code: 'ERR_OUT_OF_RANGE', 35 }); 36 closeSync(fd); 37})); 38 39const filename2 = join(tmpdir.path, 'test2.txt'); 40 41// Make sure negative length's don't cause aborts either 42 43open(filename2, 'w+', common.mustSucceed((fd) => { 44 assert.throws(() => { 45 write(fd, Buffer.alloc(0), 0, -1, common.mustNotCall()); 46 }, { 47 code: 'ERR_OUT_OF_RANGE', 48 }); 49 assert.throws(() => { 50 writeSync(fd, Buffer.alloc(0), 0, -1); 51 }, { 52 code: 'ERR_OUT_OF_RANGE', 53 }); 54 closeSync(fd); 55})); 56