{"record":{"id":"14355823e2c5e705","repo":"parallax/jsPDF","slug":"invalid-graphics-extension-block","errorCode":null,"errorMessage":"Invalid graphics extension block.","messagePattern":"Invalid graphics extension block\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/libs/omggif.js","lineNumber":510,"sourceCode":"              loop_count = buf[p++] | (buf[p++] << 8);\n              p++; // Skip terminator.\n            } else {\n              // We don't know what it is, just try to get past it.\n              p += 12;\n              while (true) {\n                // Seek through subblocks.\n                var block_size = buf[p++];\n                // Bad block size (ex: undefined from an out of bounds read).\n                if (!(block_size >= 0)) throw Error(\"Invalid block size\");\n                if (block_size === 0) break; // 0 size is terminator\n                p += block_size;\n              }\n            }\n            break;\n\n          case 0xf9: // Graphics Control Extension\n            if (buf[p++] !== 0x4 || buf[p + 4] !== 0)\n              throw new Error(\"Invalid graphics extension block.\");\n            var pf1 = buf[p++];\n            delay = buf[p++] | (buf[p++] << 8);\n            transparent_index = buf[p++];\n            if ((pf1 & 1) === 0) transparent_index = null;\n            disposal = (pf1 >> 2) & 0x7;\n            p++; // Skip terminator.\n            break;\n\n          case 0xfe: // Comment Extension.\n            while (true) {\n              // Seek through subblocks.\n              var block_size = buf[p++];\n              // Bad block size (ex: undefined from an out of bounds read).\n              if (!(block_size >= 0)) throw Error(\"Invalid block size\");\n              if (block_size === 0) break; // 0 size is terminator\n              // console.log(buf.slice(p, p+block_size).toString('ascii'));\n              p += block_size;\n            }","sourceCodeStart":492,"sourceCodeEnd":528,"githubUrl":"https://github.com/parallax/jsPDF/blob/a3930ce03a585a26b2c76d12a0f413ce96f6d1a3/src/libs/omggif.js#L492-L528","documentation":"Thrown by GifReader while parsing a Graphics Control Extension (0xF9) sub-block when the block size byte is not 4 or the terminator byte at p+4 is not 0. Per spec a GCE is exactly 4 bytes followed by a 0x00 block terminator; any deviation indicates a malformed or truncated GIF.","triggerScenarios":"Decoding a GIF whose GCE has the wrong block size (corruption); a truncated stream where bytes read as undefined; bit-flip damage in the extension header.","commonSituations":"Re-compressed or re-saved GIFs by a buggy encoder; files truncated during download; hand-crafted/edited GIFs with incorrect extension framing.","solutions":["Re-encode the GIF with a conformant encoder (ImageMagick, gifsicle, ffmpeg).","Validate file integrity / re-download if truncation is suspected.","Wrap GifReader construction in try-catch and fall back to a re-encoded copy."],"exampleFix":"// before\nvar reader = new GifReader(buffer);\nvar frame0 = reader.frameInfo(0);\n// after\ntry {\n  var reader = new GifReader(buffer);\n} catch (e) {\n  // re-encode via a known-good tool then retry\n  reader = new GifReader(reencodedBuffer);\n}","handlingStrategy":"try-catch","validationCode":"function looksIntactGif(buf){ return buf && buf.length >= 6 && buf[0]===0x47 && buf[1]===0x49 && buf[2]===0x46; }","typeGuard":null,"tryCatchPattern":"try { var reader = new GifReader(buffer); } catch (e) { if (/Invalid graphics extension block/.test(e.message)) { reader = new GifReader(reencodedBuffer); } else throw e; }","preventionTips":["Re-encode GIFs from untrusted sources with a conformant tool","Verify download completeness before parsing"],"tags":["gif","omggif","image","file-format","corruption","parsing"],"backgroundTag":null,"analyzedSha":"a3930ce03a585a26b2c76d12a0f413ce96f6d1a3","analyzedAt":"2026-08-13T05:33:39.648Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}