@@ -31,25 +31,40 @@ const expected = Buffer.from('xyz\n');
3131
3232function test ( bufferAsync , bufferSync , expected ) {
3333 fs . read ( fd ,
34- bufferAsync ,
35- 0 ,
36- expected . length ,
37- 0 ,
38- common . mustCall ( ( err , bytesRead ) => {
39- assert . ifError ( err ) ;
40- assert . strictEqual ( bytesRead , expected . length ) ;
41- assert . deepStrictEqual ( bufferAsync , expected ) ;
42- } ) ) ;
34+ bufferAsync ,
35+ 0 ,
36+ expected . length ,
37+ 0 ,
38+ common . mustCall ( ( err , bytesRead ) => {
39+ assert . ifError ( err ) ;
40+ assert . strictEqual ( bytesRead , expected . length ) ;
41+ assert . deepStrictEqual ( bufferAsync , expected ) ;
42+ } ) ) ;
4343
4444 const r = fs . readSync ( fd , bufferSync , 0 , expected . length , 0 ) ;
4545 assert . deepStrictEqual ( bufferSync , expected ) ;
4646 assert . strictEqual ( r , expected . length ) ;
4747}
4848
4949test ( Buffer . allocUnsafe ( expected . length ) ,
50- Buffer . allocUnsafe ( expected . length ) ,
51- expected ) ;
50+ Buffer . allocUnsafe ( expected . length ) ,
51+ expected ) ;
5252
5353test ( new Uint8Array ( expected . length ) ,
54- new Uint8Array ( expected . length ) ,
55- Uint8Array . from ( expected ) ) ;
54+ new Uint8Array ( expected . length ) ,
55+ Uint8Array . from ( expected ) ) ;
56+
57+ {
58+ // Reading beyond file length (3 in this case) should return no data.
59+ // This is a test for a bug where reads > uint32 would return data
60+ // from the current position in the file.
61+ const fd = fs . openSync ( filepath , 'r' ) ;
62+ const pos = 0xffffffff + 1 ; // max-uint32 + 1
63+ const nRead = fs . readSync ( fd , Buffer . alloc ( 1 ) , 0 , 1 , pos ) ;
64+ assert . strictEqual ( nRead , 0 ) ;
65+
66+ fs . read ( fd , Buffer . alloc ( 1 ) , 0 , 1 , pos , common . mustCall ( ( err , nRead ) => {
67+ assert . ifError ( err ) ;
68+ assert . strictEqual ( nRead , 0 ) ;
69+ } ) ) ;
70+ }
0 commit comments