{"record":{"id":"70380e0fa501cbe9","repo":"parallax/jsPDF","slug":"x-y-invalid","errorCode":null,"errorMessage":"x/y invalid.","messagePattern":"x/y invalid\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/libs/omggif.js","lineNumber":145,"sourceCode":"    buf[p++] = loop_count & 0xff;\n    buf[p++] = (loop_count >> 8) & 0xff;\n    buf[p++] = 0x00; // Terminator.\n  }\n\n  var ended = false;\n\n  this.addFrame = function(x, y, w, h, indexed_pixels, opts) {\n    if (ended === true) {\n      --p;\n      ended = false;\n    } // Un-end.\n\n    opts = opts === undefined ? {} : opts;\n\n    // TODO(deanm): Bounds check x, y.  Do they need to be within the virtual\n    // canvas width/height, I imagine?\n    if (x < 0 || y < 0 || x > 65535 || y > 65535)\n      throw new Error(\"x/y invalid.\");\n\n    if (w <= 0 || h <= 0 || w > 65535 || h > 65535)\n      throw new Error(\"Width/Height invalid.\");\n\n    if (indexed_pixels.length < w * h)\n      throw new Error(\"Not enough pixels for the frame size.\");\n\n    var using_local_palette = true;\n    var palette = opts.palette;\n    if (palette === undefined || palette === null) {\n      using_local_palette = false;\n      palette = global_palette;\n    }\n\n    if (palette === undefined || palette === null)\n      throw new Error(\"Must supply either a local or global palette.\");\n\n    var num_colors = check_palette_and_num_colors(palette);","sourceCodeStart":127,"sourceCodeEnd":163,"githubUrl":"https://github.com/parallax/jsPDF/blob/a3930ce03a585a26b2c76d12a0f413ce96f6d1a3/src/libs/omggif.js#L127-L163","documentation":"Thrown by GifWriter.addFrame when the frame's top-left coordinates x or y are negative or exceed 65535. Frame position is stored as unsigned 16-bit fields in the Image Descriptor, so any value outside 0..65535 is rejected. (Note: bounds against the canvas width/height are explicitly a TODO and NOT checked.)","triggerScenarios":"Calling addFrame(-5, 0, ...) for an off-canvas frame; passing x/y derived from a centering calc that goes negative; values > 65535 from large-canvas code.","commonSituations":"Sprite/packing algorithms that allow negative offsets; animation frames positioned relative to a moving origin; unit confusion producing huge coordinates.","solutions":["Clamp x and y to 0..65535 (typically 0 and within canvas bounds).","If you need off-canvas content, crop the pixels instead of using negative offsets.","Validate coordinates are non-negative integers before addFrame."],"exampleFix":"// before\ngw.addFrame(offsetX, offsetY, w, h, pixels);\n// after\nvar x = Math.max(0, Math.min(65535, Math.floor(offsetX)));\nvar y = Math.max(0, Math.min(65535, Math.floor(offsetY)));\ngw.addFrame(x, y, w, h, pixels);","handlingStrategy":"validation","validationCode":"function clampCoord(c){ c = Math.floor(c); return c < 0 ? 0 : c > 65535 ? 65535 : c; }\ngw.addFrame(clampCoord(x), clampCoord(y), w, h, pixels);","typeGuard":"function isValidFrameCoord(v){ return Number.isInteger(v) && v >= 0 && v <= 65535; }","tryCatchPattern":"try { gw.addFrame(x, y, w, h, pixels); } catch (e) { if (/x\\/y invalid/.test(e.message)) { /* clamp coords */ } else throw e; }","preventionTips":["Clamp offsets to non-negative integers","Crop rather than using negative offsets"],"tags":["gif","omggif","image","animation","validation","coordinates"],"backgroundTag":null,"analyzedSha":"a3930ce03a585a26b2c76d12a0f413ce96f6d1a3","analyzedAt":"2026-08-13T05:33:39.648Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}