BabylonJS/Babylon.js · error
zlib: trailing deflate data
Error message
zlib: trailing deflate data
What it means
After the final deflate block, inflateZlib expects the reader to sit exactly at the 4-byte Adler-32 trailer (input.byteLength - 4). If bytes remain before the trailer, it throws 'zlib: trailing deflate data' — the stream contains more compressed blocks than needed for the declared expected length, indicating concatenated streams or junk data.
Source
Thrown at packages/dev/loaders/src/FBX/parsers/zlibInflate.ts:59
switch (blockType) {
case 0:
inflateStoredBlock(reader, output);
break;
case 1:
inflateCompressedBlock(reader, output, getFixedLiteralLengthTree(), getFixedDistanceTree());
break;
case 2: {
const { literalLengthTree, distanceTree } = readDynamicTrees(reader);
inflateCompressedBlock(reader, output, literalLengthTree, distanceTree);
break;
}
default:
throw new Error("deflate: invalid block type");
}
}
if (reader.byteOffset < input.byteLength - 4) {
throw new Error("zlib: trailing deflate data");
}
output.finish();
const expectedAdler = ((input[input.byteLength - 4] << 24) | (input[input.byteLength - 3] << 16) | (input[input.byteLength - 2] << 8) | input[input.byteLength - 1]) >>> 0;
if (output.adler32() !== expectedAdler) {
throw new Error("zlib: adler32 mismatch");
}
return output.bytes;
}
class BitReader {
private bitBuffer = 0;
private bitCount = 0;
public constructor(
private readonly input: Uint8Array,
public byteOffset: number,
View on GitHub (pinned to 0592b347b8)
Solutions
- Re-export or re-compress the FBX payload as a single zlib stream
- Check that the record's compressedLength exactly matches one zlib stream (header + deflate + 4-byte adler)
- If you control the pipeline, avoid concatenating streams — compress once
- Trim any junk bytes between the deflate end and the trailer if you can regenerate the file
Defensive patterns
Strategy: validation
Validate before calling
// exactly one zlib stream: header + payload + 4-byte adler
if (compressed.byteLength !== expectedStreamLength(compressed, expectedLength)) {
throw new Error('FBX compressed array length does not match a single zlib stream');
} Try / catch
try {
return inflateZlib(compressed, expectedLength);
} catch (e) {
if ((e as Error).message === 'zlib: trailing deflate data') {
throw new Error('FBX array contains concatenated or padded zlib data — re-export', { cause: e });
}
throw e;
} Prevention
- Compress each FBX array as exactly one zlib stream
- Ensure compressedLength covers header+deflate+4-byte adler only
- Strip post-processing scripts that append bytes to compressed regions
When it happens
Trigger: A compressed FBX array payload containing concatenated zlib streams, extra bytes appended between the deflate stream and the Adler trailer, or a compressedLength field larger than the actual single stream.
Common situations: Custom exporters concatenating compressed chunks; files post-processed by scripts that append data; mismatched length fields after byte-level edits.
Related errors
- zlib: invalid header
- zlib: invalid expected length
- zlib: unexpected end of input
- zlib: preset dictionary not supported
- zlib: adler32 mismatch
AI-assisted analysis of BabylonJS/Babylon.js@0592b347b8 (2026-08-30).
Data as JSON: /api/errors/04e0d181312da82d.
Report an issue: GitHub.