{"record":{"id":"04e0d181312da82d","repo":"BabylonJS/Babylon.js","slug":"zlib-trailing-deflate-data","errorCode":null,"errorMessage":"zlib: trailing deflate data","messagePattern":"zlib: trailing deflate data","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/dev/loaders/src/FBX/parsers/zlibInflate.ts","lineNumber":59,"sourceCode":"        switch (blockType) {\r\n            case 0:\r\n                inflateStoredBlock(reader, output);\r\n                break;\r\n            case 1:\r\n                inflateCompressedBlock(reader, output, getFixedLiteralLengthTree(), getFixedDistanceTree());\r\n                break;\r\n            case 2: {\r\n                const { literalLengthTree, distanceTree } = readDynamicTrees(reader);\r\n                inflateCompressedBlock(reader, output, literalLengthTree, distanceTree);\r\n                break;\r\n            }\r\n            default:\r\n                throw new Error(\"deflate: invalid block type\");\r\n        }\r\n    }\r\n\r\n    if (reader.byteOffset < input.byteLength - 4) {\r\n        throw new Error(\"zlib: trailing deflate data\");\r\n    }\r\n\r\n    output.finish();\r\n    const expectedAdler = ((input[input.byteLength - 4] << 24) | (input[input.byteLength - 3] << 16) | (input[input.byteLength - 2] << 8) | input[input.byteLength - 1]) >>> 0;\r\n    if (output.adler32() !== expectedAdler) {\r\n        throw new Error(\"zlib: adler32 mismatch\");\r\n    }\r\n\r\n    return output.bytes;\r\n}\r\n\r\nclass BitReader {\r\n    private bitBuffer = 0;\r\n    private bitCount = 0;\r\n\r\n    public constructor(\r\n        private readonly input: Uint8Array,\r\n        public byteOffset: number,\r","sourceCodeStart":41,"sourceCodeEnd":77,"githubUrl":"https://github.com/BabylonJS/Babylon.js/blob/0592b347b8a4ee0236089ea86a749cacfdb266d8/packages/dev/loaders/src/FBX/parsers/zlibInflate.ts#L41-L77","documentation":"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.","triggerScenarios":"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.","commonSituations":"Custom exporters concatenating compressed chunks; files post-processed by scripts that append data; mismatched length fields after byte-level edits.","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"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// exactly one zlib stream: header + payload + 4-byte adler\nif (compressed.byteLength !== expectedStreamLength(compressed, expectedLength)) {\n  throw new Error('FBX compressed array length does not match a single zlib stream');\n}","typeGuard":null,"tryCatchPattern":"try {\n  return inflateZlib(compressed, expectedLength);\n} catch (e) {\n  if ((e as Error).message === 'zlib: trailing deflate data') {\n    throw new Error('FBX array contains concatenated or padded zlib data — re-export', { cause: e });\n  }\n  throw e;\n}","preventionTips":["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"],"tags":["zlib","compression","corrupt-data","fbx"],"backgroundTag":"corrupt-compressed-data","analyzedSha":"0592b347b8a4ee0236089ea86a749cacfdb266d8","analyzedAt":"2026-08-30T15:11:20.442Z","schemaVersion":2},"datasetVersion":"2026-08-30T18:17:15.746Z"}