{"record":{"id":"28134055b72b9356","repo":"BabylonJS/Babylon.js","slug":"incorrect-openexr-format","errorCode":null,"errorMessage":"Incorrect OpenEXR format","messagePattern":"Incorrect OpenEXR format","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/dev/core/src/Materials/Textures/Loaders/EXR/exrLoader.header.ts","lineNumber":87,"sourceCode":"// // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\r\n// // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\r\n// // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r\n// //\r\n// ///////////////////////////////////////////////////////////////////////////\r\n\r\n// // End of OpenEXR license -------------------------------------------------\r\n\r\nconst EXR_MAGIC = 20000630;\r\n\r\n/**\r\n * Gets the EXR header\r\n * @param dataView defines the data view to read from\r\n * @param offset defines the offset to start reading from\r\n * @returns the header\r\n */\r\nexport function GetExrHeader(dataView: DataView, offset: DataCursor): IEXRHeader {\r\n    if (dataView.getUint32(0, true) != EXR_MAGIC) {\r\n        throw new Error(\"Incorrect OpenEXR format\");\r\n    }\r\n\r\n    const version = dataView.getUint8(4);\r\n\r\n    const specData = dataView.getUint8(5); // fullMask\r\n    const spec = {\r\n        singleTile: !!(specData & 2),\r\n        longName: !!(specData & 4),\r\n        deepFormat: !!(specData & 8),\r\n        multiPart: !!(specData & 16),\r\n    };\r\n\r\n    offset.value = 8;\r\n\r\n    const headerData: any = {};\r\n\r\n    let keepReading = true;\r\n\r","sourceCodeStart":69,"sourceCodeEnd":105,"githubUrl":"https://github.com/BabylonJS/Babylon.js/blob/0592b347b8a4ee0236089ea86a749cacfdb266d8/packages/dev/core/src/Materials/Textures/Loaders/EXR/exrLoader.header.ts#L69-L105","documentation":"GetExrHeader reads the first 4 bytes of the DataView and compares them to EXR_MAGIC (0x76, 0x2f, 0x31, 0x01 — the OpenEXR magic number 0x01312f76 little-endian). If they do not match, the input is not an OpenEXR file at all, so parsing stops immediately.","triggerScenarios":"Raised in GetExrHeader (called by header) whenever dataView.getUint32(0, true) !== EXR_MAGIC: passing a PNG/JPG/HDR/EXR-variant renamed to .exr, an HTML error page saved as .exr, an empty/zero-length buffer, or a byte-swapped/big-endian dump.","commonSituations":"404 responses saved as texture files, wrong file chosen in an asset pipeline, pipeline step writing a different format with an .exr extension, or loading a .tx/.dpx mislabeled as EXR.","solutions":["Verify the file path/URL points to a real .exr (check `file scene.exr` says 'OpenEXR image data')","Check the HTTP response was 200 and the server did not return an HTML error page","Confirm the ArrayBuffer passed to the loader is the complete file, not a slice or a re-encoded texture","Re-export the asset as OpenEXR from the DCC tool"],"exampleFix":"// before: blindly loading whatever the URL returns\nconst res = await fetch(url);\nloader.load(await res.blob());\n// after: guard status and magic bytes\nconst res = await fetch(url);\nif (!res.ok) throw new Error(\"fetch failed: \" + res.status);\nconst buf = new Uint8Array(await res.arrayBuffer());\nif (!(buf[0] === 0x76 && buf[1] === 0x2f && buf[2] === 0x31 && buf[3] === 0x01)) throw new Error(\"not an EXR file\");","handlingStrategy":"validation","validationCode":"async function fetchExr(url: string): Promise<ArrayBuffer> {\n  const res = await fetch(url);\n  if (!res.ok) throw new Error(\"HTTP \" + res.status + \" for EXR\");\n  const buf = await res.arrayBuffer();\n  if (buf.byteLength < 8 || new DataView(buf).getUint32(0, true) !== 0x01312f76) throw new Error(\"not an OpenEXR file: \" + url);\n  return buf;\n}","typeGuard":"function isOpenExrBuffer(buf: ArrayBuffer): boolean {\n  return buf.byteLength >= 4 && new DataView(buf).getUint32(0, true) === 0x01312f76;\n}","tryCatchPattern":"try {\n  await loader.loadAsync(file);\n} catch (e) {\n  if (/Incorrect OpenEXR format/.test(String(e))) {\n    console.error(\"File at url is not EXR — check path, HTTP status and file type\");\n    return loadPlaceholderTexture();\n  }\n  throw e;\n}","preventionTips":["Check HTTP status codes before treating a response as an asset","Run `file asset.exr` in CI to catch mislabeled textures","Validate the 0x76 0x2f 0x31 0x01 magic bytes before loading","Avoid renaming files of a different format to .exr"],"tags":["exr","magic-number","wrong-file-format"],"backgroundTag":"invalid-file-magic-number","analyzedSha":"0592b347b8a4ee0236089ea86a749cacfdb266d8","analyzedAt":"2026-08-30T15:11:20.442Z","schemaVersion":2},"datasetVersion":"2026-08-30T18:17:15.746Z"}