mozilla/pdf.js · error · Error
Invalid version: ${version}
Error message
Invalid version: ${version} What it means
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.
Source
Thrown at src/display/editor/drawers/signaturedraw.js:782
.then(async () => {
await writer.ready;
await writer.close();
})
.catch(() => {});
let data = null;
let offset = 0;
for await (const chunk of readable) {
data ||= new Uint8Array(new Uint32Array(chunk.buffer, 0, 4)[0]);
data.set(chunk, offset);
offset += chunk.length;
}
// We take a bit too much data for the header but it's fine.
const header = new Uint32Array(data.buffer, 0, data.length >> 2);
const version = header[1];
if (version !== 0) {
throw new Error(`Invalid version: ${version}`);
}
const width = header[2];
const height = header[3];
const areContours = header[4] === 0;
const thickness = header[5];
const numberOfDrawings = header[6];
const bufferType = header[7];
const outlines = [];
const diffsOffset =
(BASE_HEADER_LENGTH + POINTS_PROPERTIES_NUMBER * numberOfDrawings) *
Uint32Array.BYTES_PER_ELEMENT;
let diffs;
switch (bufferType) {
case Int8Array.BYTES_PER_ELEMENT:
diffs = new Int8Array(data.buffer, diffsOffset);
break;
case Int16Array.BYTES_PER_ELEMENT:View on GitHub (pinned to 5903d58d58)
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.
Example fix
// before
const drawer = SignatureDrawer.fromStream(storedBytes);
// after
const header = new Uint32Array(storedBytes.buffer, 0, 2);
if (header[1] !== 0) {
// old or corrupt signature data — discard and let the user re-draw
return null;
}
const drawer = SignatureDrawer.fromStream(storedBytes); Defensive patterns
Strategy: validation
Validate before calling
function signatureVersionOk(bytes) {
if (bytes.byteLength < 8) return false;
const header = new Uint32Array(bytes.buffer, bytes.byteOffset, 2);
return header[1] === 0;
}
if (!signatureVersionOk(storedBytes)) { /* discard */ } Type guard
const isV0SignatureBlob = (b: Uint8Array): boolean => b.byteLength >= 8 && new Uint32Array(b.buffer, b.byteOffset, 2)[1] === 0;
Try / catch
try {
SignatureDrawer.fromStream(storedBytes);
} catch (e) {
if (e.message.startsWith('Invalid version:')) { /* drop and re-capture */ }
else throw e;
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: Persisting signatures across pdfjs versions that changed the format; storage corruption (DB, IndexedDB) that altered the bytes; tests feeding random Uint8Arrays to the drawer.
Related errors
- Worker was destroyed.
- `BinaryDataFactory` not initialized, see the `useWorkerFetch
- Please provide binary data as `Uint8Array`, rather than `Buf
- Invalid PDF binary data: either TypedArray, string, or array
- app.formsVersion is read-only
AI-assisted analysis of mozilla/pdf.js@5903d58d58 (2026-08-13).
Data as JSON: /api/errors/a5a2580ae7936817.
Report an issue: GitHub.