{"record":{"id":"a5a2580ae7936817","repo":"mozilla/pdf.js","slug":"invalid-version-version","errorCode":null,"errorMessage":"Invalid version: ${version}","messagePattern":"Invalid version: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/display/editor/drawers/signaturedraw.js","lineNumber":782,"sourceCode":"        .then(async () => {\n          await writer.ready;\n          await writer.close();\n        })\n        .catch(() => {});\n\n      let data = null;\n      let offset = 0;\n      for await (const chunk of readable) {\n        data ||= new Uint8Array(new Uint32Array(chunk.buffer, 0, 4)[0]);\n        data.set(chunk, offset);\n        offset += chunk.length;\n      }\n\n      // We take a bit too much data for the header but it's fine.\n      const header = new Uint32Array(data.buffer, 0, data.length >> 2);\n      const version = header[1];\n      if (version !== 0) {\n        throw new Error(`Invalid version: ${version}`);\n      }\n      const width = header[2];\n      const height = header[3];\n      const areContours = header[4] === 0;\n      const thickness = header[5];\n      const numberOfDrawings = header[6];\n      const bufferType = header[7];\n      const outlines = [];\n      const diffsOffset =\n        (BASE_HEADER_LENGTH + POINTS_PROPERTIES_NUMBER * numberOfDrawings) *\n        Uint32Array.BYTES_PER_ELEMENT;\n      let diffs;\n\n      switch (bufferType) {\n        case Int8Array.BYTES_PER_ELEMENT:\n          diffs = new Int8Array(data.buffer, diffsOffset);\n          break;\n        case Int16Array.BYTES_PER_ELEMENT:","sourceCodeStart":764,"sourceCodeEnd":800,"githubUrl":"https://github.com/mozilla/pdf.js/blob/5903d58d58e4dd9ce6ffa3834aea8480f06b4ada/src/display/editor/drawers/signaturedraw.js#L764-L800","documentation":"Thrown by the signature-drawing decoder in signaturedraw.js when parsing the binary signature-stroke data stream and the second 32-bit header word (version) is not 0. The format is version-locked; only version 0 is supported, so any other value means the data is corrupt, truncated, or produced by an incompatible signature encoder.","triggerScenarios":"Loading a saved signature whose serialized blob is from a newer/older encoder; a truncated or partially-downloaded signature stream; passing arbitrary binary data into the signature draw path.","commonSituations":"Persisting signatures across pdfjs versions that changed the format; storage corruption (DB, IndexedDB) that altered the bytes; tests feeding random Uint8Arrays to the drawer.","solutions":["Regenerate the signature in the current pdfjs version and re-save it.","If migrating, write a one-time converter or discard old signatures.","Validate the blob length and magic header before invoking the decoder."],"exampleFix":"// before\nconst drawer = SignatureDrawer.fromStream(storedBytes);\n\n// after\nconst header = new Uint32Array(storedBytes.buffer, 0, 2);\nif (header[1] !== 0) {\n  // old or corrupt signature data — discard and let the user re-draw\n  return null;\n}\nconst drawer = SignatureDrawer.fromStream(storedBytes);","handlingStrategy":"validation","validationCode":"function signatureVersionOk(bytes) {\n  if (bytes.byteLength < 8) return false;\n  const header = new Uint32Array(bytes.buffer, bytes.byteOffset, 2);\n  return header[1] === 0;\n}\nif (!signatureVersionOk(storedBytes)) { /* discard */ }","typeGuard":"const isV0SignatureBlob = (b: Uint8Array): boolean =>\n  b.byteLength >= 8 && new Uint32Array(b.buffer, b.byteOffset, 2)[1] === 0;","tryCatchPattern":"try {\n  SignatureDrawer.fromStream(storedBytes);\n} catch (e) {\n  if (e.message.startsWith('Invalid version:')) { /* drop and re-capture */ }\n  else throw e;\n}","preventionTips":["Version your persisted signature blobs at the storage layer.","When upgrading pdfjs, plan a migration or a clean re-capture for old signatures.","Validate header before invoking the decoder."],"tags":["signature","binary-data","version"],"backgroundTag":null,"analyzedSha":"5903d58d58e4dd9ce6ffa3834aea8480f06b4ada","analyzedAt":"2026-08-13T02:28:27.364Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}