{"record":{"id":"a98de314e2f8c472","repo":"mozilla/pdf.js","slug":"unknown-compression-method-in-flate-stream-cmf","errorCode":null,"errorMessage":"Unknown compression method in flate stream: ${cmf}, ${flg}","messagePattern":"Unknown compression method in flate stream: (.+?), (.+?)","errorType":"exception","errorClass":"FormatError","httpStatus":null,"severity":"error","filePath":"src/core/flate_stream.js","lineNumber":139,"sourceCode":"  5,\n];\n\nclass FlateStream extends DecodeStream {\n  #isAsync = true;\n\n  constructor(str, maybeLength) {\n    super(maybeLength);\n\n    this.stream = str;\n    this.dict = str.dict;\n\n    const cmf = str.getByte();\n    const flg = str.getByte();\n    if (cmf === -1 || flg === -1) {\n      throw new FormatError(`Invalid header in flate stream: ${cmf}, ${flg}`);\n    }\n    if ((cmf & 0x0f) !== 0x08) {\n      throw new FormatError(\n        `Unknown compression method in flate stream: ${cmf}, ${flg}`\n      );\n    }\n    if (((cmf << 8) + flg) % 31 !== 0) {\n      throw new FormatError(`Bad FCHECK in flate stream: ${cmf}, ${flg}`);\n    }\n    if (flg & 0x20) {\n      throw new FormatError(`FDICT bit set in flate stream: ${cmf}, ${flg}`);\n    }\n\n    this.codeSize = 0;\n    this.codeBuf = 0;\n  }\n\n  async getImageData(length, _decoderOptions) {\n    const data = await this.asyncGetBytes();\n    if (!data) {\n      return this.getBytes(length);","sourceCodeStart":121,"sourceCodeEnd":157,"githubUrl":"https://github.com/mozilla/pdf.js/blob/5903d58d58e4dd9ce6ffa3834aea8480f06b4ada/src/core/flate_stream.js#L121-L157","documentation":"Thrown by the FlateStream constructor when the CMF byte's low nibble (compression method) is not 8 — the only legal value per RFC 1950 (deflate). Any other method (0-7, 9-15) is not a deflate stream; PDF.js supports only method 8. This is the second of four sequential header-validation guards and fires only after the header bytes were successfully read (error 117 did not trigger).","triggerScenarios":"A PDF stream declared as /FlateDecode whose first two bytes do not encode compression method 8 — e.g. the bytes are actually a raw deflate stream (no zlib wrapper), a gzip stream (method 0 with different framing), or random/corrupt data. Fires during FlateStream construction when the method nibble check fails.","commonSituations":"Producers that wrote raw deflate (no zlib header) but declared /FlateDecode, PDFs whose streams were re-compressed with a different algorithm by a faulty tool, or byte-level corruption of the stream header. Also seen when a stream was accidentally double-compressed or mislabeled.","solutions":["Re-export the PDF through Ghostscript or Acrobat to normalize stream compression to standard zlib/deflate.","If authoring, ensure your zlib writer emits the standard RFC-1950 header (CM=8, CINFO<=7) before the deflate payload.","Repair with qpdf which can rebuild and re-encode stream filters.","Isolate the failing page/stream and continue processing others via per-page try/catch."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  await page.render({ canvasContext, viewport });\n} catch (e) {\n  if (e.name === 'FormatError' && /Unknown compression method in flate stream/.test(e.message)) {\n    // stream is not standard zlib/deflate — re-encode the PDF\n  } else throw e;\n}","preventionTips":["Re-export PDFs through Ghostscript or Acrobat to normalize all streams to standard zlib/deflate.","When authoring, ensure your zlib writer emits the RFC-1950 header (CM=8, CINFO<=7).","Screen PDFs with qpdf --check to catch mislabeled stream filters."],"tags":["pdf","flate","zlib","compression-method","stream","format-error"],"backgroundTag":null,"analyzedSha":"5903d58d58e4dd9ce6ffa3834aea8480f06b4ada","analyzedAt":"2026-08-13T02:28:27.364Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}