{"record":{"id":"21a5c6e9447cc67d","repo":"mozilla/pdf.js","slug":"no-domain-or-range","errorCode":null,"errorMessage":"No domain or range","messagePattern":"No domain or range","errorType":"exception","errorClass":"FormatError","httpStatus":null,"severity":"error","filePath":"src/core/function.js","lineNumber":172,"sourceCode":"    }\n    return function (src, srcOffset, dest, destOffset) {\n      for (let i = 0, ii = fnArray.length; i < ii; i++) {\n        fnArray[i](src, srcOffset, dest, destOffset + i);\n      }\n    };\n  }\n\n  static constructSampled(factory, fn, dict) {\n    // See chapter 3, page 109 of the PDF reference\n    function interpolate(x, xmin, xmax, ymin, ymax) {\n      return ymin + (x - xmin) * ((ymax - ymin) / (xmax - xmin));\n    }\n\n    const domain = toNumberArray(dict.getArray(\"Domain\"));\n    const range = toNumberArray(dict.getArray(\"Range\"));\n\n    if (!domain || !range) {\n      throw new FormatError(\"No domain or range\");\n    }\n\n    const inputSize = domain.length / 2;\n    const outputSize = range.length / 2;\n\n    const size = toNumberArray(dict.getArray(\"Size\"));\n    const bps = dict.get(\"BitsPerSample\");\n    const order = dict.get(\"Order\") || 1;\n    if (order !== 1) {\n      // No description how cubic spline interpolation works in PDF32000:2008\n      // As in poppler, ignoring order, linear interpolation may work as good\n      info(\"No support for cubic spline interpolation: \" + order);\n    }\n\n    let encode = toNumberArray(dict.getArray(\"Encode\"));\n    if (!encode) {\n      encode = [];\n      for (let i = 0; i < inputSize; ++i) {","sourceCodeStart":154,"sourceCodeEnd":190,"githubUrl":"https://github.com/mozilla/pdf.js/blob/5903d58d58e4dd9ce6ffa3834aea8480f06b4ada/src/core/function.js#L154-L190","documentation":"Thrown inside PDFFunction.constructSampled (FunctionType 0) when either the /Domain or /Range array on the function dictionary is missing or not a pure numeric array. Both are required by the PDF spec to define the input and output dimensionality of a sampled (table-lookup) function; without them interpolation cannot be set up.","triggerScenarios":"A FunctionType 0 dictionary that lacks /Domain or /Range, or where one resolves to a non-number array (e.g. contains refs to non-numeric objects). Reached when rendering gradients, Indexed color spaces, or shading patterns that reference a sampled function.","commonSituations":"Corrupt/truncated PDFs, or PDFs produced by tools that omit Range on sampled functions. Encountered while opening specific test files known to have malformed CalRGB/Indexed lookups.","solutions":["Validate the PDF in Acrobat; if it works there, report the file to pdf.js maintainers as the constructor may need a fallback.","If generating PDFs, always emit both /Domain and /Range as flat numeric arrays of even length for every type-0 function.","Catch FormatError around render and skip the affected page/annotation.","Run the PDF through qpdf --check to detect missing required function entries."],"exampleFix":"// generating a sampled function: always include Domain and Range\n/* before\n<< /FunctionType 0 /Domain [0 1] /Size [256] /BitsPerSample 8 /DataSource (...) >>\n*/\n// after\n<< /FunctionType 0 /Domain [0 1] /Range [0 1 0 1 0 1] /Size [256] /BitsPerSample 8 /DataSource (...) >>","handlingStrategy":"try-catch","validationCode":"function hasSampledFunctionDomainRange(dict) {\n  const d = dict.getArray?.('Domain');\n  const r = dict.getArray?.('Range');\n  return Array.isArray(d) && Array.isArray(r) &&\n    d.every(Number.isFinite) && r.every(Number.isFinite) &&\n    d.length % 2 === 0 && r.length % 2 === 0;\n}","typeGuard":"function isNumberArrayOfEvenLength(arr) {\n  return Array.isArray(arr) && arr.length % 2 === 0 &&\n    arr.every(x => typeof x === 'number' && Number.isFinite(x));\n}","tryCatchPattern":"try { await page.render({ canvasContext }).promise; }\ncatch (err) {\n  if (err?.name === 'FormatError' && /No domain or range/.test(err.message)) {\n    console.warn('Malformed sampled function; degrading page.');\n  } else throw err;\n}","preventionTips":["When authoring Type 0 functions, always emit /Domain and /Range as numeric arrays.","Use qpdf --check to catch missing required function entries.","Isolate per-page rendering with try/catch."],"tags":["pdf","function","sampled","parsing","malformed-pdf"],"backgroundTag":null,"analyzedSha":"5903d58d58e4dd9ce6ffa3834aea8480f06b4ada","analyzedAt":"2026-08-13T02:28:27.364Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}