Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion lib/canvas.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,11 @@ Canvas.prototype.createJPEGStream = function(options){
Canvas.prototype.syncJPEGStream =
Canvas.prototype.createSyncJPEGStream = function(options){
options = options || {};
// Don't allow the buffer size to exceed the size of the canvas (#674)
var maxBufSize = this.width * this.height * 4;
var clampedBufSize = Math.min(options.bufsize || 4096, maxBufSize);
return new JPEGStream(this, {
bufsize: options.bufsize || 4096
bufsize: clampedBufSize
, quality: options.quality || 75
, progressive: options.progressive || false
});
Expand Down
10 changes: 10 additions & 0 deletions test/canvas.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -786,4 +786,14 @@ describe('Canvas', function () {
done(err);
});
});

it('Canvas#jpegStream() should clamp buffer size (#674)', function (done) {
var c = new Canvas(10, 10);
var SIZE = 10 * 1024 * 1024;
var s = c.jpegStream({bufsize: SIZE});
s.on('data', function (chunk) {
assert(chunk.length < SIZE);
});
s.on('end', done);
})
});