{"record":{"id":"51b49fcadd0079be","repo":"mozilla/pdf.js","slug":"xobject-should-be-a-stream","errorCode":null,"errorMessage":"XObject should be a stream","messagePattern":"XObject should be a stream","errorType":"exception","errorClass":"FormatError","httpStatus":null,"severity":"error","filePath":"src/core/evaluator.js","lineNumber":1794,"sourceCode":"                }\n\n                let xobj = xobjs.getRaw(name);\n                if (xobj instanceof Ref) {\n                  const cachedImage =\n                    localImageCache.getByRef(xobj) ||\n                    self._regionalImageCache.getByRef(xobj) ||\n                    self.globalImageCache.getData(xobj, self.pageIndex);\n                  if (cachedImage) {\n                    addCachedImageOps(operatorList, cachedImage);\n                    resolveXObject();\n                    return;\n                  }\n\n                  xobj = xref.fetch(xobj);\n                }\n\n                if (!(xobj instanceof BaseStream)) {\n                  throw new FormatError(\"XObject should be a stream\");\n                }\n\n                const type = xobj.dict.get(\"Subtype\");\n                if (!(type instanceof Name)) {\n                  throw new FormatError(\"XObject should have a Name subtype\");\n                }\n\n                if (type.name === \"Form\") {\n                  stateManager.save();\n                  self\n                    .buildFormXObject(\n                      resources,\n                      xobj,\n                      null,\n                      operatorList,\n                      task,\n                      stateManager.state.clone({ newPath: true }),\n                      localColorSpaceCache,","sourceCodeStart":1776,"sourceCodeEnd":1812,"githubUrl":"https://github.com/mozilla/pdf.js/blob/5903d58d58e4dd9ce6ffa3834aea8480f06b4ada/src/core/evaluator.js#L1776-L1812","documentation":"FormatError thrown when a named XObject resource, after being fetched from the xref (if it was an indirect Ref), is not a BaseStream. PDF XObjects must be streams; a non-stream entry is corrupt or the wrong object type.","triggerScenarios":"The XObject resource dictionary resolves the name to something that is not a stream (a dict, number, null, or broken indirect reference), so the 'instanceof BaseStream' check fails.","commonSituations":"Truncated PDFs where the stream object is missing/corrupt, indirect references that resolve to the wrong object, or generators that place a dictionary where a stream XObject is required.","solutions":["Enable ignoreErrors: true to skip the bad XObject.","Repair the PDF so the XObject entry is a valid stream.","Upgrade PDF.js."],"exampleFix":"// before\ngetDocument({ data }); // non-stream XObject aborts render\n\n// after\ngetDocument({ data, ignoreErrors: true }); // bad XObject skipped","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  await page.render({ canvasContext, viewport }).promise;\n} catch (e) {\n  if (/XObject should be a stream/.test(e.message)) {\n    await reloadWith({ ignoreErrors: true });\n  } else throw e;\n}","preventionTips":["Enable ignoreErrors for untrusted PDFs.","Repair broken indirect references in source PDFs.","Upgrade PDF.js."],"tags":["pdf","xobject","malformed-pdf","rendering"],"backgroundTag":null,"analyzedSha":"5903d58d58e4dd9ce6ffa3834aea8480f06b4ada","analyzedAt":"2026-08-13T02:28:27.364Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}