File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -516,15 +516,19 @@ class CompressionStream : public AsyncWrap,
516516 if (!args[2 ]->Uint32Value (context).To (&in_off)) return ;
517517 if (!args[3 ]->Uint32Value (context).To (&in_len)) return ;
518518
519- CHECK (Buffer::IsWithinBounds (in_off, in_len, Buffer::Length (in_buf)));
519+ if (!Buffer::IsWithinBounds (in_off, in_len, Buffer::Length (in_buf))) {
520+ return THROW_ERR_OUT_OF_RANGE (env, " input buffer is out of bounds" );
521+ }
520522 in = Buffer::Data (in_buf) + in_off;
521523 }
522524
523525 CHECK (Buffer::HasInstance (args[4 ]));
524526 Local<Object> out_buf = args[4 ].As <Object>();
525527 if (!args[5 ]->Uint32Value (context).To (&out_off)) return ;
526528 if (!args[6 ]->Uint32Value (context).To (&out_len)) return ;
527- CHECK (Buffer::IsWithinBounds (out_off, out_len, Buffer::Length (out_buf)));
529+ if (!Buffer::IsWithinBounds (out_off, out_len, Buffer::Length (out_buf))) {
530+ return THROW_ERR_OUT_OF_RANGE (env, " output buffer is out of bounds" );
531+ }
528532 out = Buffer::Data (out_buf) + out_off;
529533
530534 CompressionStream* ctx;
Original file line number Diff line number Diff line change @@ -52,6 +52,43 @@ nonStringInputs.forEach(common.mustCall((input) => {
5252 } ) ;
5353} , nonStringInputs . length ) ) ;
5454
55+ const spoofedLength = new Uint8Array ( 1 ) . fill ( 0x41 ) ;
56+ Object . defineProperty ( spoofedLength , 'length' , { get : ( ) => 5000 } ) ;
57+ Object . defineProperty ( spoofedLength , 'byteLength' , { get : ( ) => 5000 } ) ;
58+
59+ [
60+ zlib . deflateSync ,
61+ zlib . gzipSync ,
62+ zlib . deflateRawSync ,
63+ zlib . unzipSync ,
64+ zlib . inflateSync ,
65+ zlib . gunzipSync ,
66+ zlib . inflateRawSync ,
67+ zlib . brotliCompressSync ,
68+ zlib . brotliDecompressSync ,
69+ zlib . zstdCompressSync ,
70+ zlib . zstdDecompressSync ,
71+ ] . forEach ( ( method ) => {
72+ assert . throws ( ( ) => {
73+ method ( spoofedLength ) ;
74+ } , {
75+ name : 'RangeError' ,
76+ code : 'ERR_OUT_OF_RANGE' ,
77+ } ) ;
78+ } ) ;
79+
80+ {
81+ const deflate = zlib . createDeflate ( ) ;
82+ deflate . _outOffset = deflate . _chunkSize + 1 ;
83+ assert . throws ( ( ) => {
84+ deflate . _processChunk ( Buffer . alloc ( 1 ) , zlib . constants . Z_FINISH ) ;
85+ } , {
86+ name : 'RangeError' ,
87+ code : 'ERR_OUT_OF_RANGE' ,
88+ } ) ;
89+ deflate . close ( ) ;
90+ }
91+
5592unzips . forEach ( common . mustCall ( ( uz , i ) => {
5693 uz . on ( 'error' , common . mustCall ( ) ) ;
5794 uz . on ( 'end' , common . mustNotCall ( ) ) ;
You can’t perform that action at this time.
0 commit comments