parallax/jsPDF · error · Error

Image dimensions exceed 512MB, which is too large.

Error message

Image dimensions exceed 512MB, which is too large.

What it means

Thrown by BmpDecoder.parseBGR before allocating the decoded pixel buffer when width*height*4 exceeds 512 MiB. The check prevents allocating an outsized Uint8Array that could exhaust memory; any BMP whose decoded RGBA size surpasses the hard limit is rejected up front.

Source

Thrown at src/libs/BMPDecoder.js:86

        green: green,
        blue: blue,
        quad: quad
      };
    }
  }
  if (this.height < 0) {
    this.height *= -1;
    this.bottom_up = false;
  }
};

BmpDecoder.prototype.parseBGR = function() {
  this.pos = this.offset;
  var bitn = "bit" + this.bitPP;
  var len = this.width * this.height * 4;

  if (len > 512 * 1024 * 1024) {
    throw new Error("Image dimensions exceed 512MB, which is too large.");
  }

  this.data = new Uint8Array(len);

  try {
    this[bitn]();
  } catch (e) {
    console.log("bit decode error:" + e);
  }
};

BmpDecoder.prototype.bit1 = function() {
  var xlen = Math.ceil(this.width / 8);
  var mode = xlen % 4;
  var y;
  for (y = this.height - 1; y >= 0; y--) {
    var line = this.bottom_up ? y : this.height - 1 - y;
    for (var x = 0; x < xlen; x++) {

View on GitHub (pinned to a3930ce03a)

Solutions

  1. Downscale or tile the image before decoding so width*height*4 stays under 512 MiB.
  2. Reject images above a safe pixel budget at upload before invoking BmpDecoder.
  3. Sanity-check parsed width/height against a reasonable max and abort early.

Example fix

// before
var bmp = new BmpDecoder(buffer); // huge dimensions
// after
if (buffer.width * buffer.height * 4 > 512 * 1024 * 1024) {
  throw new Error('Image too large; downscale before decoding');
}
var bmp = new BmpDecoder(buffer);
Defensive patterns

Strategy: validation

Validate before calling

function bmpByteSize(w,h){ return w*h*4; }
if (bmpByteSize(width,height) <= 512*1024*1024) { new BmpDecoder(buffer); }

Type guard

function fitsBmpLimit(w,h){ return w > 0 && h > 0 && w*h*4 <= 512*1024*1024; }

Prevention

When it happens

Trigger: Decoding a BMP with very large width/height (e.g. tens of thousands of pixels per side) where the 4-bytes-per-pixel buffer would exceed 536870912 bytes. Crafted or misreported header dimensions; a header whose width/height fields were parsed incorrectly producing huge values.

Common situations: Processing scanned/print-resolution images; hostile/crafted BMPs with inflated dimension fields; downstream code that scales images before decode but still passes the original huge buffer.

Related errors


AI-assisted analysis of parallax/jsPDF@a3930ce03a (2026-08-13). Data as JSON: /api/errors/33a9dc090a267fba. Report an issue: GitHub.