File tree Expand file tree Collapse file tree 2 files changed +14
-1
lines changed Expand file tree Collapse file tree 2 files changed +14
-1
lines changed Original file line number Diff line number Diff line change @@ -185,8 +185,11 @@ Canvas.prototype.createJPEGStream = function(options){
185185Canvas . prototype . syncJPEGStream =
186186Canvas . prototype . createSyncJPEGStream = function ( options ) {
187187 options = options || { } ;
188+ // Don't allow the buffer size to exceed the size of the canvas (#674)
189+ var maxBufSize = this . width * this . height * 4 ;
190+ var clampedBufSize = Math . min ( options . bufsize || 4096 , maxBufSize ) ;
188191 return new JPEGStream ( this , {
189- bufsize : options . bufsize || 4096
192+ bufsize : clampedBufSize
190193 , quality : options . quality || 75
191194 , progressive : options . progressive || false
192195 } ) ;
Original file line number Diff line number Diff line change @@ -786,4 +786,14 @@ describe('Canvas', function () {
786786 done ( err ) ;
787787 } ) ;
788788 } ) ;
789+
790+ it ( 'Canvas#jpegStream() should clamp buffer size (#674)' , function ( done ) {
791+ var c = new Canvas ( 10 , 10 ) ;
792+ var SIZE = 10 * 1024 * 1024 ;
793+ var s = c . jpegStream ( { bufsize : SIZE } ) ;
794+ s . on ( 'data' , function ( chunk ) {
795+ assert ( chunk . length < SIZE ) ;
796+ } ) ;
797+ s . on ( 'end' , done ) ;
798+ } )
789799} ) ;
You can’t perform that action at this time.
0 commit comments