{"record":{"id":"da55143c99702b27","repo":"mozilla/pdf.js","slug":"whitepoint-missing-required-for-color-space-calg","errorCode":null,"errorMessage":"WhitePoint missing - required for color space CalGray","messagePattern":"WhitePoint missing - required for color space CalGray","errorType":"exception","errorClass":"FormatError","httpStatus":null,"severity":"error","filePath":"src/core/colorspace.js","lineNumber":817,"sourceCode":"    }\n  }\n\n  getOutputLength(inputLength, alpha01) {\n    return ((inputLength / 4) * (3 + alpha01)) | 0;\n  }\n}\n\n/**\n * CalGrayCS: Based on \"PDF Reference, Sixth Ed\", p.245\n *\n * The default color is `new Float32Array([0])`.\n */\nclass CalGrayCS extends ColorSpace {\n  constructor(whitePoint, blackPoint, gamma) {\n    super(\"CalGray\", 1);\n\n    if (!whitePoint) {\n      throw new FormatError(\n        \"WhitePoint missing - required for color space CalGray\"\n      );\n    }\n    // Translate arguments to spec variables.\n    [this.XW, this.YW, this.ZW] = whitePoint;\n    [this.XB, this.YB, this.ZB] = blackPoint || [0, 0, 0];\n    this.G = gamma || 1;\n\n    // Validate variables as per spec.\n    if (this.XW < 0 || this.ZW < 0 || this.YW !== 1) {\n      throw new FormatError(\n        `Invalid WhitePoint components for ${this.name}, no fallback available`\n      );\n    }\n\n    if (this.XB < 0 || this.YB < 0 || this.ZB < 0) {\n      info(`Invalid BlackPoint for ${this.name}, falling back to default.`);\n      this.XB = this.YB = this.ZB = 0;","sourceCodeStart":799,"sourceCodeEnd":835,"githubUrl":"https://github.com/mozilla/pdf.js/blob/5903d58d58e4dd9ce6ffa3834aea8480f06b4ada/src/core/colorspace.js#L799-L835","documentation":"Thrown by the CalGrayCS constructor when the /WhitePoint array is missing or falsy for a /CalGray color space. Per the PDF spec WhitePoint is mandatory for CalGray calibration, and pdf.js refuses to invent a default because the resulting color would be wrong.","triggerScenarios":"Constructing CalGrayCS with whitePoint = null/undefined/[], or parsing a PDF /CalGray dictionary that lacks a /WhitePoint entry.","commonSituations":"Corrupt PDF missing the /WhitePoint array; a faulty color-profile extractor; hand-authored PDF with an incomplete CalGray dict.","solutions":["Repair the PDF to include a valid /WhitePoint array (commonly [X, 1, Z] with Y normalized to 1).","Update pdf.js."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":"function hasWhitePoint(csDict) {\n  return Array.isArray(csDict.get('WhitePoint')) && csDict.get('WhitePoint').length === 3;\n}","tryCatchPattern":"try {\n  cs = ColorSpace.parse(res, xref, cs, pdfFunctionFactory);\n} catch (e) {\n  if (e instanceof FormatError && /WhitePoint missing.*CalGray/.test(e.message)) {\n    console.warn('CalGray missing WhitePoint, falling back', e);\n    cs = null;\n  } else throw e;\n}","preventionTips":["Validate untrusted PDFs before rendering.","When generating /CalGray color spaces, always include /WhitePoint.","Keep pdf.js updated.","Treat CalGray construction failures as non-fatal; fall back to DeviceGray."],"tags":["colorspace","calgray","cie","parsing","pdf"],"backgroundTag":null,"analyzedSha":"5903d58d58e4dd9ce6ffa3834aea8480f06b4ada","analyzedAt":"2026-08-13T02:28:27.364Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}