BabylonJS/Babylon.js · error
deflate: invalid code length symbol
Error message
deflate: invalid code length symbol
What it means
The code-length alphabet in a dynamic block only permits symbols 0-18; the tree is built from 19 lengths, so this default branch is defensive — it fires if decode somehow returns a symbol outside 0-18 (should be impossible with a valid tree), signalling internal corruption of the decoded lengths. Practically, it surfaces on the same corrupt/misaligned streams as the other huffman errors.
Source
Thrown at packages/dev/loaders/src/FBX/parsers/zlibInflate.ts:392
let repeatedValue: number;
switch (symbol) {
case 16:
if (lengths.length === 0) {
throw new Error("deflate: invalid code length repeat");
}
repeatedValue = lengths[lengths.length - 1];
repeatLength = reader.readBits(2) + 3;
break;
case 17:
repeatedValue = 0;
repeatLength = reader.readBits(3) + 3;
break;
case 18:
repeatedValue = 0;
repeatLength = reader.readBits(7) + 11;
break;
default:
throw new Error("deflate: invalid code length symbol");
}
if (lengths.length + repeatLength > count) {
throw new Error("deflate: invalid code length repeat");
}
for (let i = 0; i < repeatLength; i++) {
lengths.push(repeatedValue);
}
}
return lengths;
}
View on GitHub (pinned to 0592b347b8)
Solutions
- Validate the payload independently with python zlib.decompress to confirm corruption
- Re-export or re-download the FBX file
- Audit any pipeline step that touches compressed array bytes in the FBX binary
- If reproducible on valid files, report with the failing payload bytes — the loader's code-length tree construction may need hardening
Defensive patterns
Strategy: try-catch
Validate before calling
try { decompressSync(payload); } catch (e) {
throw new Error("Payload rejected by reference zlib decoder — FBX file corrupt", { cause: e as Error });
} Try / catch
try {
const out = inflateZlib(payload, expectedLength);
} catch (e) {
if (e instanceof Error && e.message === "deflate: invalid code length symbol") {
throw new Error("Out-of-range code-length symbol — deeply corrupt FBX payload", { cause: e });
}
throw e;
} Prevention
- Cross-validate with a mature zlib implementation before suspecting the custom inflater
- Audit pipelines that post-process FBX binaries for accidental byte rewriting
- Hash-verify assets at download time
When it happens
Trigger: readCodeLengths decodes a symbol >18 from the code-length tree during a type-2 block — only reachable if the tree was built from data that assigned codes to out-of-range symbols, i.e. deeply corrupt input.
Common situations: Severely corrupted FBX payloads; a bitstream that is not deflate at all but passed earlier header checks; bug in custom tooling that rewrote compressed array bytes.
Related errors
- deflate: missing end-of-block code
- deflate: invalid code length repeat
- deflate: invalid huffman code
- deflate: invalid stored block length
- deflate: invalid literal/length symbol
AI-assisted analysis of BabylonJS/Babylon.js@0592b347b8 (2026-08-30).
Data as JSON: /api/errors/4d8b227caa31cf4d.
Report an issue: GitHub.