Browse Source

Clamp JPEG buffer size. Fixes #674

v1.x
Zach Bjornson 9 years ago
parent
commit
6edfe44d53
  1. 5
      lib/canvas.js
  2. 10
      test/canvas.test.js

5
lib/canvas.js

@ -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
});

10
test/canvas.test.js

@ -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);
})
});

Loading…
Cancel
Save