{"record":{"id":"877f8653aefac7c8","repo":"BabylonJS/Babylon.js","slug":"hufdecode-issues-877f86","errorCode":null,"errorMessage":"HufDecode issues","messagePattern":"HufDecode issues","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/dev/core/src/Materials/Textures/Loaders/EXR/exrLoader.compression.huf.ts","lineNumber":395,"sourceCode":"\r\n                    if (lc >= l) {\r\n                        if (HufCode(encodingTable[pl.p[j]]) == ((c >> (lc - l)) & ((1 << l) - 1))) {\r\n                            lc -= l;\r\n\r\n                            const gCode = GetCode(pl.p[j], rlc, c, lc, array, offset, outBuffer, outOffset, outBufferEndOffset);\r\n\r\n                            if (gCode) {\r\n                                c = gCode.c;\r\n                                lc = gCode.lc;\r\n                            }\r\n\r\n                            break;\r\n                        }\r\n                    }\r\n                }\r\n\r\n                if (j == pl.lit) {\r\n                    throw new Error(\"HufDecode issues\");\r\n                }\r\n            }\r\n        }\r\n    }\r\n\r\n    const i = (8 - ni) & 7;\r\n\r\n    c >>= i;\r\n    lc -= i;\r\n\r\n    while (lc > 0) {\r\n        const pl = decodingTable[(c << (HUF_DECBITS - lc)) & HUF_DECMASK];\r\n\r\n        if (pl.len) {\r\n            lc -= pl.len;\r\n\r\n            const gCode = GetCode(pl.lit, rlc, c, lc, array, offset, outBuffer, outOffset, outBufferEndOffset);\r\n            if (gCode) {\r","sourceCodeStart":377,"sourceCodeEnd":413,"githubUrl":"https://github.com/BabylonJS/Babylon.js/blob/0592b347b8a4ee0236089ea86a749cacfdb266d8/packages/dev/core/src/Materials/Textures/Loaders/EXR/exrLoader.compression.huf.ts#L377-L413","documentation":"In HufDecode's overflow path, after following the table entry's pointer (`pl.p`) and scanning up to `pl.lit` candidate symbols, if no symbol matches the remaining bits (`j == pl.lit`) the bitstream cannot be represented by the code table, so the loader throws \"HufDecode issues\". This is the final integrity check when decoding huf-compressed EXR data.","triggerScenarios":"Huf EXR bitstream contains a bit pattern that fails to match any symbol in the overflow list for a long code — payload corrupted, misaligned by earlier bad reads, or produced by a non-canonical encoder.","commonSituations":"Corrupted/partial downloads; EXR assets written by buggy custom encoders; binary assets altered by build tools or asset pipelines (e.g. minifiers/gzip applied twice); opening a non-EXR file with an .exr extension.","solutions":["Verify the asset integrity (size/checksum) and re-download or re-export the EXR.","Re-encode the EXR with a reference implementation using a non-huf compression.","Check the serving pipeline for accidental content-transformations of binary files.","Wrap EXR loading in try/catch with a fallback image and user-facing message."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"async function preflightExr(url) {\n  const res = await fetch(url);\n  const buf = new Uint8Array(await res.arrayBuffer());\n  const dv = new DataView(buf.buffer);\n  return buf.length > 8 && dv.getUint32(0, true) === 20000630;\n}","typeGuard":"function isExrBuffer(data) {\n  return data instanceof ArrayBuffer &&\n    data.byteLength >= 8 &&\n    new DataView(data).getUint32(0, true) === 20000630;\n}","tryCatchPattern":"try {\n  loadExrTexture('scene.exr');\n} catch (e) {\n  if (e instanceof Error && e.message === 'HufDecode issues') {\n    console.error('EXR huf bitstream does not match its code table; asset is corrupt.');\n    swapToFallbackTexture();\n  } else { throw e; }\n}","preventionTips":["Ship EXRs exported with mainstream tools and non-huf compression.","Verify asset hashes in CI so corrupted binaries never reach production.","Ensure hosting layers don't alter binary responses (disable transforms for .exr).","Implement a global texture-load error handler with a fallback image."],"tags":["exr","huf-decompression","corrupt-data","texture-loading"],"backgroundTag":"exr-huf-invalid-table-entry","analyzedSha":"0592b347b8a4ee0236089ea86a749cacfdb266d8","analyzedAt":"2026-08-30T15:11:20.442Z","schemaVersion":2},"datasetVersion":"2026-08-30T18:17:15.746Z"}