{"record":{"id":"33a9dc090a267fba","repo":"parallax/jsPDF","slug":"image-dimensions-exceed-512mb-which-is-too-large","errorCode":null,"errorMessage":"Image dimensions exceed 512MB, which is too large.","messagePattern":"Image dimensions exceed 512MB, which is too large\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/libs/BMPDecoder.js","lineNumber":86,"sourceCode":"        green: green,\n        blue: blue,\n        quad: quad\n      };\n    }\n  }\n  if (this.height < 0) {\n    this.height *= -1;\n    this.bottom_up = false;\n  }\n};\n\nBmpDecoder.prototype.parseBGR = function() {\n  this.pos = this.offset;\n  var bitn = \"bit\" + this.bitPP;\n  var len = this.width * this.height * 4;\n\n  if (len > 512 * 1024 * 1024) {\n    throw new Error(\"Image dimensions exceed 512MB, which is too large.\");\n  }\n\n  this.data = new Uint8Array(len);\n\n  try {\n    this[bitn]();\n  } catch (e) {\n    console.log(\"bit decode error:\" + e);\n  }\n};\n\nBmpDecoder.prototype.bit1 = function() {\n  var xlen = Math.ceil(this.width / 8);\n  var mode = xlen % 4;\n  var y;\n  for (y = this.height - 1; y >= 0; y--) {\n    var line = this.bottom_up ? y : this.height - 1 - y;\n    for (var x = 0; x < xlen; x++) {","sourceCodeStart":68,"sourceCodeEnd":104,"githubUrl":"https://github.com/parallax/jsPDF/blob/a3930ce03a585a26b2c76d12a0f413ce96f6d1a3/src/libs/BMPDecoder.js#L68-L104","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Downscale or tile the image before decoding so width*height*4 stays under 512 MiB.","Reject images above a safe pixel budget at upload before invoking BmpDecoder.","Sanity-check parsed width/height against a reasonable max and abort early."],"exampleFix":"// before\nvar bmp = new BmpDecoder(buffer); // huge dimensions\n// after\nif (buffer.width * buffer.height * 4 > 512 * 1024 * 1024) {\n  throw new Error('Image too large; downscale before decoding');\n}\nvar bmp = new BmpDecoder(buffer);","handlingStrategy":"validation","validationCode":"function bmpByteSize(w,h){ return w*h*4; }\nif (bmpByteSize(width,height) <= 512*1024*1024) { new BmpDecoder(buffer); }","typeGuard":"function fitsBmpLimit(w,h){ return w > 0 && h > 0 && w*h*4 <= 512*1024*1024; }","tryCatchPattern":null,"preventionTips":["Reject or downscale images over ~23000x23000","Check dimensions before decode, not after"],"tags":["bmp","image","memory","validation","dimensions"],"backgroundTag":null,"analyzedSha":"a3930ce03a585a26b2c76d12a0f413ce96f6d1a3","analyzedAt":"2026-08-13T05:33:39.648Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}