parallax/jsPDF · error · Error
Invalid graphics extension block.
Error message
Invalid graphics extension block.
What it means
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.
Source
Thrown at src/libs/omggif.js:510
loop_count = buf[p++] | (buf[p++] << 8);
p++; // Skip terminator.
} else {
// We don't know what it is, just try to get past it.
p += 12;
while (true) {
// Seek through subblocks.
var block_size = buf[p++];
// Bad block size (ex: undefined from an out of bounds read).
if (!(block_size >= 0)) throw Error("Invalid block size");
if (block_size === 0) break; // 0 size is terminator
p += block_size;
}
}
break;
case 0xf9: // Graphics Control Extension
if (buf[p++] !== 0x4 || buf[p + 4] !== 0)
throw new Error("Invalid graphics extension block.");
var pf1 = buf[p++];
delay = buf[p++] | (buf[p++] << 8);
transparent_index = buf[p++];
if ((pf1 & 1) === 0) transparent_index = null;
disposal = (pf1 >> 2) & 0x7;
p++; // Skip terminator.
break;
case 0xfe: // Comment Extension.
while (true) {
// Seek through subblocks.
var block_size = buf[p++];
// Bad block size (ex: undefined from an out of bounds read).
if (!(block_size >= 0)) throw Error("Invalid block size");
if (block_size === 0) break; // 0 size is terminator
// console.log(buf.slice(p, p+block_size).toString('ascii'));
p += block_size;
}View on GitHub (pinned to a3930ce03a)
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.
Example fix
// before
var reader = new GifReader(buffer);
var frame0 = reader.frameInfo(0);
// after
try {
var reader = new GifReader(buffer);
} catch (e) {
// re-encode via a known-good tool then retry
reader = new GifReader(reencodedBuffer);
} Defensive patterns
Strategy: try-catch
Validate before calling
function looksIntactGif(buf){ return buf && buf.length >= 6 && buf[0]===0x47 && buf[1]===0x49 && buf[2]===0x46; } Try / catch
try { var reader = new GifReader(buffer); } catch (e) { if (/Invalid graphics extension block/.test(e.message)) { reader = new GifReader(reencodedBuffer); } else throw e; } Prevention
- Re-encode GIFs from untrusted sources with a conformant tool
- Verify download completeness before parsing
When it happens
Trigger: 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.
Common situations: Re-compressed or re-saved GIFs by a buggy encoder; files truncated during download; hand-crafted/edited GIFs with incorrect extension framing.
Related errors
- Unknown graphic control label: 0x" + buf[p - 1].toString(16)
- Invalid GIF 87a/89a header.
- Width/Height invalid.
- Invalid code/color length, must be power of 2 and 2 .. 256.
- Background index out of range.
AI-assisted analysis of parallax/jsPDF@a3930ce03a (2026-08-13).
Data as JSON: /api/errors/14355823e2c5e705.
Report an issue: GitHub.