BabylonJS/Babylon.js · error · Error

Wrong HUF_ENCSIZE

Error message

Wrong HUF_ENCSIZE

What it means

HufUncompress validated the minimum/maximum symbol indices (im/iM) read from the Huffman table header of a PIZ-compressed block against HUF_ENCSIZE (65537). A value outside [0, HUF_ENCSIZE) proves the compressed stream is not a valid OpenEXR huf block, so the loader aborts instead of indexing arrays out of bounds.

Source

Thrown at packages/dev/core/src/Materials/Textures/Loaders/EXR/exrLoader.compression.huf.ts:440

    return true;
}

/** @internal */
export function HufUncompress(array: Uint8Array, dataView: DataView, offset: DataCursor, nCompressed: number, outBuffer: Uint16Array, nRaw: number) {
    const outOffset: DataCursor = { value: 0 };
    const initialInOffset = offset.value;

    const im = ParseUint32(dataView, offset);
    const iM = ParseUint32(dataView, offset);

    offset.value += 4;

    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);

View on GitHub (pinned to 0592b347b8)

Solutions

  1. Verify the .exr integrity (size, checksum) and re-download/re-export it
  2. Load the file with exrheader or another EXR reader to confirm it is valid PIZ data
  3. Check the EXR offset table is being parsed correctly (earlier header errors shift block offsets)
  4. Re-export the texture using ZIP/ZIPS compression instead of PIZ
Defensive patterns

Strategy: validation

Validate before calling

// confirm the file is a well-formed EXR before attempting PIZ decode
if (new DataView(buf).getUint32(0, true) !== 0x01312f76 || buf.byteLength < 64) throw new Error("invalid or truncated EXR");

Try / catch

try {
  await loader.loadAsync(exrFile);
} catch (e) {
  if (/Wrong HUF_ENCSIZE/.test(String(e))) {
    console.error("PIZ block corrupt — re-export the EXR with ZIP compression");
    return loadFallbackTexture();
  }
  throw e;
}

Prevention

When it happens

Trigger: Raised in HufUncompress (called by UncompressPIZ) immediately after parsing the four leading uint32 fields when im or iM is negative or >= HUF_ENCSIZE — i.e. the bytes at the huf block start are not a real huf table.

Common situations: Corrupt or truncated downloads, wrong chunk offsets after a malformed EXR header, or a file saved by a non-conformant writer.

Related errors


AI-assisted analysis of BabylonJS/Babylon.js@0592b347b8 (2026-08-30). Data as JSON: /api/errors/a02ad44747203341. Report an issue: GitHub.