{"record":{"id":"ad396d8f5182d5cb","repo":"dotnet/runtime","slug":"posix-memalign-failed-for-icu-data","errorCode":null,"errorMessage":"posix_memalign failed for ICU data","messagePattern":"posix_memalign failed for ICU data","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"critical","filePath":"src/native/libs/Common/JavaScript/host/assets.ts","lineNumber":186,"sourceCode":"        _ems_.HEAPU32[outDataStartPtr as any >>> 2] = assembly.ptr;\n        // int64_t target\n        _ems_.HEAPU32[outSize as any >>> 2] = assembly.length;\n        _ems_.HEAPU32[((outSize as any) + 4) >>> 2] = 0;\n        return true;\n    }\n    _ems_.dotnetLogger.debug(`Assembly not found: '${path}'`);\n    _ems_.HEAPU32[outDataStartPtr as any >>> 2] = 0;\n    _ems_.HEAPU32[outSize as any >>> 2] = 0;\n    _ems_.HEAPU32[((outSize as any) + 4) >>> 2] = 0;\n    return false;\n}\n\nexport function loadIcuData(bytes: Uint8Array) {\n    const sp = _ems_.stackSave();\n    try {\n        const ptrPtr = _ems_.stackAlloc(sizeOfPtr);\n        if (_ems_._posix_memalign(ptrPtr as any, 16, bytes.length)) {\n            throw new Error(\"posix_memalign failed for ICU data\");\n        }\n\n        const ptr = _ems_.HEAPU32[ptrPtr as any >>> 2];\n        _ems_.HEAPU8.set(bytes, ptr >>> 0);\n\n        const result = _ems_._wasm_load_icu_data(ptr as unknown as VoidPtr);\n        if (!result) {\n            throw new Error(\"Failed to initialize ICU data\");\n        }\n    } finally {\n        _ems_.stackRestore(sp);\n    }\n}\n\nexport function installVfsFile(bytes: Uint8Array, asset: VfsAsset) {\n    const virtualName: string = typeof (asset.virtualPath) === \"string\"\n        ? asset.virtualPath\n        : asset.name;","sourceCodeStart":168,"sourceCodeEnd":204,"githubUrl":"https://github.com/dotnet/runtime/blob/60108ba66eb7d1d12f595480091b4ad80a24b172/src/native/libs/Common/JavaScript/host/assets.ts#L168-L204","documentation":"Thrown by loadIcuData() (src/native/libs/Common/JavaScript/host/assets.ts:181) when _posix_memalign fails to allocate the 16-byte-aligned buffer for ICU (globalization) data. ICU data files (icudt.dat) are large, so this allocation is the one most likely to hit the heap ceiling.","triggerScenarios":"fetchIcu() downloads the ICU asset, waits for the native module, then calls loadIcuData(bytes). Inside, posix_memalign(ptrPtr,16,bytes.length) returns non-zero because the heap cannot fit the ICU data blob.","commonSituations":"Loading the full icudt.dat into a runtime with too little maximum memory; shipping the wrong (too large) ICU shard for the app; a memory-constrained device whose maximum memory is capped low.","solutions":["Use a smaller ICU data file (culture-specific ICU shards / hybrid globalization) to reduce the allocation size.","Raise the runtime maximum WebAssembly.Memory.","Avoid loading ICU if globalization is not needed (configure globalization mode/invariant culture)."],"exampleFix":"<!-- before: full ICU loaded into small-memory runtime -->\n\n<!-- after: ship a culture-specific ICU shard -->\n<ItemGroup>\n  <BlazorWebAssemblyLoadAllGlobalizationData>false</BlazorWebAssemblyLoadAllGlobalizationData>\n</ItemGroup>\n<!-- and/or raise memory: { \"memory\": { \"maximum\": 2048 } } -->","handlingStrategy":"try-catch","validationCode":"// pick a smaller ICU shard when memory is tight\nfunction recommendedIcuAsset(): string {\n  return useHybridGlobalization ? 'icudt_hybrid.dat' : 'icudt.dat';\n}","typeGuard":null,"tryCatchPattern":"try {\n  await dotnetBrowserHostExports.loadIcuData(bytes);\n} catch (err) {\n  if (/posix_memalign failed for ICU data/.test(String((err as Error).message))) {\n    // switch to a culture-specific ICU shard or raise maximum memory\n  }\n  throw err;\n}","preventionTips":["Use culture-specific or hybrid ICU shards instead of the full icudt.dat on low-memory devices.","Raise the runtime maximum memory to accommodate ICU data.","Skip ICU entirely if the app can run under invariant globalization."],"tags":["memory","icu","globalization","native"],"backgroundTag":null,"analyzedSha":"60108ba66eb7d1d12f595480091b4ad80a24b172","analyzedAt":"2026-08-10T18:54:11.478Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}