Skip to content

Commit ea6e54c

Browse files
committed
Issue #60: Detect zero-size 2D modules and throw an error.
1 parent dc4900b commit ea6e54c

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

bwipjs.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ BWIPJS.prototype.setextent = function() {
305305
}
306306
// source is an 8-bit bitmask
307307
// This implementation is optimized for 2D bar codes. That is, it does not
308-
// distort the image due to rounding errors. Every pixel is sized
308+
// distort the image due to rounding errors. Every pixel is scaled
309309
// identically, so the resulting image may be smaller by a few pixels than
310310
// the scaling factor would require. And the transform matrix is not used.
311311
BWIPJS.prototype.imagemask = function(width, height, source) {
@@ -316,7 +316,10 @@ BWIPJS.prototype.imagemask = function(width, height, source) {
316316
var rl = Math.ceil(width / 8); // row length (bytes per row)
317317
var y0 = Math.floor(this.g_tdy) + height * dy;
318318
var x0;
319-
319+
320+
if (!dx || !dy) {
321+
throw new Error('Image scaled to zero size.');
322+
}
320323
for (var y = 0; y < height; y++) {
321324
x0 = Math.floor(this.g_tdx);
322325
y0 -= dy;

0 commit comments

Comments
 (0)