{"record":{"id":"3f76d314faf509fe","repo":"BabylonJS/Babylon.js","slug":"zlib-output-length-mismatch","errorCode":null,"errorMessage":"zlib: output length mismatch","messagePattern":"zlib: output length mismatch","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/dev/loaders/src/FBX/parsers/zlibInflate.ts","lineNumber":156,"sourceCode":"            this.bitCount += 8;\r\n        }\r\n    }\r\n}\r\n\r\nclass OutputWriter {\r\n    private offset = 0;\r\n    private adlerA = 1;\r\n    private adlerB = 0;\r\n\r\n    public readonly bytes: Uint8Array;\r\n\r\n    public constructor(expectedLength: number) {\r\n        this.bytes = new Uint8Array(expectedLength);\r\n    }\r\n\r\n    public writeByte(value: number): void {\r\n        if (this.offset >= this.bytes.byteLength) {\r\n            throw new Error(\"zlib: output length mismatch\");\r\n        }\r\n        const byte = value & 0xff;\r\n        this.bytes[this.offset++] = byte;\r\n        this.adlerA += byte;\r\n        this.adlerB += this.adlerA;\r\n        this.adlerA %= ADLER_MOD;\r\n        this.adlerB %= ADLER_MOD;\r\n    }\r\n\r\n    public copy(distance: number, length: number): void {\r\n        if (distance <= 0 || distance > this.offset) {\r\n            throw new Error(\"deflate: distance out of range\");\r\n        }\r\n        for (let i = 0; i < length; i++) {\r\n            this.writeByte(this.bytes[this.offset - distance]);\r\n        }\r\n    }\r\n\r","sourceCodeStart":138,"sourceCodeEnd":174,"githubUrl":"https://github.com/BabylonJS/Babylon.js/blob/0592b347b8a4ee0236089ea86a749cacfdb266d8/packages/dev/loaders/src/FBX/parsers/zlibInflate.ts#L138-L174","documentation":"writeByte tried to store a byte past the end of the pre-allocated output Uint8Array sized to expectedLength. The decompressed stream produced more bytes than the caller told inflateZlib to expect (the expected length passed by the FBX array parser). Because the implementation writes exactly expectedLength bytes or fails, any surplus means the declared array length and the actual compressed content disagree.","triggerScenarios":"inflateZlib(input, expectedLength) is called with an expectedLength smaller than the true decompressed size — e.g. an FBX node whose array length field was read incorrectly (wrong offset, endianness, or stale file version), or a compressed payload that actually decodes to more elements.","commonSituations":"FBX files edited/re-exported between versions so element counts changed but cached metadata didn't; parsing the wrong node's length field; corruption that flips bits in the length header; copy-paste of array sizes between attribute nodes.","solutions":["Verify expectedLength comes from the correct FBX node field and matches the element count of the array being decoded.","Check offset/endianness when reading the array length from the binary FBX header.","Re-export the FBX file to regenerate consistent length and payload data.","Log expectedLength versus the offset at failure to see how many extra bytes the stream produced, then fix the source of the count."],"exampleFix":"// before\nconst count = view.getUint32(nodeOffset + 4, true); // wrong field offset\nconst arr = inflateZlib(payload, count * 8);\n// after\nconst count = view.getUint32(nodeOffset, true); // correct length field\nconst arr = inflateZlib(payload, count * 8);","handlingStrategy":"validation","validationCode":"// sanity-check declared element count against payload plausibility\nif (!Number.isInteger(expectedLength) || expectedLength < 0) throw new Error(\"bad expectedLength\");\nif (payload.byteLength < 6) throw new Error(\"payload too short for declared array\");","typeGuard":null,"tryCatchPattern":"try {\n  return inflateZlib(payload, expectedLength);\n} catch (e) {\n  if (e instanceof Error && e.message === \"zlib: output length mismatch\") {\n    throw new Error(`decompressed size exceeds declared length ${expectedLength} — check FBX array length field`);\n  }\n  throw e;\n}","preventionTips":["Read the array length field at the correct node offset with correct endianness.","Distinguish element count vs byte count when computing expectedLength.","Re-export FBX files after producer/tool version changes.","Log expectedLength on failure to compare against actual decoded size."],"tags":["zlib","length-mismatch","fbx","corrupt-data"],"backgroundTag":"zlib-output-length-mismatch","analyzedSha":"0592b347b8a4ee0236089ea86a749cacfdb266d8","analyzedAt":"2026-08-30T15:11:20.442Z","schemaVersion":2},"datasetVersion":"2026-08-30T18:17:15.746Z"}