mozilla/pdf.js · error · FormatError

Invalid WhitePoint components for ${this.name}, no fallback

Error message

Invalid WhitePoint components for ${this.name}, no fallback available

What it means

Thrown by CalGrayCS when the WhitePoint fails spec validation: XW < 0, ZW < 0, or YW !== 1. WhitePoint must be a CIE-relative white with Y normalized to 1; BlackPoint and gamma have fallbacks but WhitePoint does not, so an invalid one is fatal.

Source

Thrown at src/core/colorspace.js:828

 * The default color is `new Float32Array([0])`.
 */
class CalGrayCS extends ColorSpace {
  constructor(whitePoint, blackPoint, gamma) {
    super("CalGray", 1);

    if (!whitePoint) {
      throw new FormatError(
        "WhitePoint missing - required for color space CalGray"
      );
    }
    // Translate arguments to spec variables.
    [this.XW, this.YW, this.ZW] = whitePoint;
    [this.XB, this.YB, this.ZB] = blackPoint || [0, 0, 0];
    this.G = gamma || 1;

    // Validate variables as per spec.
    if (this.XW < 0 || this.ZW < 0 || this.YW !== 1) {
      throw new FormatError(
        `Invalid WhitePoint components for ${this.name}, no fallback available`
      );
    }

    if (this.XB < 0 || this.YB < 0 || this.ZB < 0) {
      info(`Invalid BlackPoint for ${this.name}, falling back to default.`);
      this.XB = this.YB = this.ZB = 0;
    }

    if (this.XB !== 0 || this.YB !== 0 || this.ZB !== 0) {
      warn(
        `${this.name}, BlackPoint: XB: ${this.XB}, YB: ${this.YB}, ` +
          `ZB: ${this.ZB}, only default values are supported.`
      );
    }

    if (this.G < 1) {
      info(

View on GitHub (pinned to 5903d58d58)

Solutions

  1. Repair the PDF so /WhitePoint has non-negative X/Z and Y exactly 1.
  2. Update pdf.js.
  3. If you generate PDFs, normalize the white point to Y=1 before writing.
Defensive patterns

Strategy: try-catch

Type guard

function isValidWhitePoint(wp) {
  return Array.isArray(wp)
    && wp.length === 3
    && wp[0] >= 0
    && wp[1] === 1
    && wp[2] >= 0;
}

Try / catch

try {
  cs = ColorSpace.parse(res, xref, cs, pdfFunctionFactory);
} catch (e) {
  if (e instanceof FormatError && /Invalid WhitePoint components/.test(e.message)) {
    console.warn('Invalid CalGray WhitePoint, falling back', e);
    cs = null;
  } else throw e;
}

Prevention

When it happens

Trigger: A /CalGray /WhitePoint array whose X or Z component is negative, or whose Y component is not exactly 1 (e.g. [0.95, 0.98, 1.08]).

Common situations: Color-managed PDF with a malformed ICC-derived WhitePoint; hand-authored PDF; rounding that left Y != 1.

Related errors


AI-assisted analysis of mozilla/pdf.js@5903d58d58 (2026-08-13). Data as JSON: /api/errors/68ccd1bc22210e0f. Report an issue: GitHub.