BabylonJS/Babylon.js · error · Error
Wrong hufUncompress
Error message
Wrong hufUncompress
What it means
After unpacking the Huffman encoding table, HufUncompress checks that the declared bit count (nBits) does not exceed the remaining compressed bytes (×8). If it does, the stream claims more payload bits than physically exist, so the data is incomplete/invalid and decoding is refused before HufDecode runs.
Source
Thrown at packages/dev/core/src/Materials/Textures/Loaders/EXR/exrLoader.compression.huf.ts:453
const nBits = ParseUint32(dataView, offset);
offset.value += 4;
if (im < 0 || im >= HUF_ENCSIZE || iM < 0 || iM >= HUF_ENCSIZE) {
throw new Error("Wrong HUF_ENCSIZE");
}
const freq = new Array(HUF_ENCSIZE);
const hdec = new Array(HUF_DECSIZE);
HufClearDecTable(hdec);
const ni = nCompressed - (offset.value - initialInOffset);
HufUnpackEncTable(array, offset, ni, im, iM, freq);
if (nBits > 8 * (nCompressed - (offset.value - initialInOffset))) {
throw new Error("Wrong hufUncompress");
}
HufBuildDecTable(freq, im, iM, hdec);
HufDecode(freq, hdec, array, offset, nBits, iM, nRaw, outBuffer, outOffset);
}
function UInt16(value: number) {
return value & 0xffff;
}
function Int16(value: number) {
const ref = UInt16(value);
return ref > 0x7fff ? ref - 0x10000 : ref;
}
function Wdec14(l: number, h: number) {
const ls = Int16(l);
View on GitHub (pinned to 0592b347b8)
Solutions
- Re-download the .exr and confirm it is not truncated
- Verify the chunk's data size and offset come from the file's scanline offset table, not a hard-coded value
- Confirm the file decompresses in a reference EXR tool
- Re-export with a non-PIZ compression to rule out a writer bug
Defensive patterns
Strategy: validation
Validate before calling
if (expectedByteLength && file.byteLength !== expectedByteLength) throw new Error("EXR truncated: got " + file.byteLength + " expected " + expectedByteLength); Try / catch
try {
await loader.loadAsync(blob);
} catch (e) {
if (/Wrong hufUncompress/.test(String(e))) {
// nBits exceeds remaining bytes → truncated block; re-fetch or use fallback asset
return loadFallbackTexture(url);
}
throw e;
} Prevention
- Enforce Content-Length checks on downloads
- Do not slice EXR ArrayBuffers manually; pass the whole file
- Validate the scanline offset table when doing custom EXR chunk parsing
- Re-export with non-PIZ compression for flaky pipelines
When it happens
Trigger: Raised in HufUncompress (called by UncompressPIZ) when nCompressed was too small — typically the scanline block size/offset used to slice the huf data was wrong or the block was truncated.
Common situations: Truncated HTTP responses, incorrectly computed nCompressed when manually reading EXR chunk data, or a corrupt offset table pointing mid-block.
Related errors
- Error in HufUnpackEncTable
- Wrong HUF_ENCSIZE
- Wrong PIZ_COMPRESSION BITMAP_SIZE
- Invalid table entry
- hufDecode issues
AI-assisted analysis of BabylonJS/Babylon.js@0592b347b8 (2026-08-30).
Data as JSON: /api/errors/84b0970651e7b782.
Report an issue: GitHub.