{"record":{"id":"8e76144801a51149","repo":"nodejs/node","slug":"u-memory-allocation-error-8e7614","errorCode":"U_MEMORY_ALLOCATION_ERROR","errorMessage":"icupkg: unable to allocate memory for swapping \\\"%s\\\"\\n","messagePattern":"icupkg: unable to allocate memory for swapping \\\\\"(.+?)\\\\\"\\\\n","errorType":"console","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"deps/icu-small/source/tools/toolutil/pkgitems.cpp","lineNumber":105,"sourceCode":"        }\n        length=pItem->length-itemHeaderLength;\n\n        if(pInfo->isBigEndian==U_IS_BIG_ENDIAN && pInfo->charsetFamily==U_CHARSET_FAMILY) {\n            bytes=pItem->data+itemHeaderLength;\n        } else {\n            UDataSwapper* ds = udata_openSwapper(static_cast<UBool>(pInfo->isBigEndian), pInfo->charsetFamily, U_IS_BIG_ENDIAN, U_CHARSET_FAMILY, &errorCode);\n            if(U_FAILURE(errorCode)) {\n                fprintf(stderr, \"icupkg: udata_openSwapper(\\\"%s\\\") failed - %s\\n\",\n                        pItem->name, u_errorName(errorCode));\n                exit(errorCode);\n            }\n\n            ds->printError=printError;\n            ds->printErrorContext=stderr;\n\n            swapped=new uint8_t[pItem->length];\n            if(swapped==nullptr) {\n                fprintf(stderr, \"icupkg: unable to allocate memory for swapping \\\"%s\\\"\\n\", pItem->name);\n                exit(U_MEMORY_ALLOCATION_ERROR);\n            }\n            swap(ds, pItem->data, pItem->length, swapped, &errorCode);\n            pInfo=::getDataInfo(swapped, pItem->length, infoLength, itemHeaderLength, &errorCode);\n            bytes=swapped+itemHeaderLength;\n            udata_closeSwapper(ds);\n        }\n    }\n\nprivate:\n    const Item *pItem;\n    const UDataInfo *pInfo;\n    const uint8_t *bytes;\n    uint8_t *swapped;\n    int32_t length;\n};\n\n// check a dependency ------------------------------------------------------ ***","sourceCodeStart":87,"sourceCodeEnd":123,"githubUrl":"https://github.com/nodejs/node/blob/1b2de5e052fc0fb95fd7fb6846dcec4ade598e9e/deps/icu-small/source/tools/toolutil/pkgitems.cpp#L87-L123","documentation":"After a successful openSwapper, pkgitems allocates `new uint8_t[pItem->length]` to hold the swapped bytes; if that returns NULL it prints the item name and exit(U_MEMORY_ALLOCATION_ERROR). With throwing new this is effectively unreachable unless pItem->length is astronomically large (corrupt length field).","triggerScenarios":"pItem->length is huge due to a corrupt/truncated .dat header (so new requests gigabytes), or genuine heap exhaustion during the swap buffer allocation. The `if(swapped==nullptr)` check fires.","commonSituations":"A damaged .dat where an item's length field is garbage, causing a multi-GB allocation attempt; OOM on a constrained build host.","solutions":["Regenerate the .dat from clean source data (likely a corrupt length field).","Sanity-check item length against the file size before trusting it.","Raise available memory if the size is legitimately large.","Inspect the .dat with `icupkg -l` and reject packages with implausibly large items."],"exampleFix":"# before\nicupkg -x corrupt.dat   # garbage length -> huge alloc -> exit 977\n# after\nicupkg -l clean.dat && icupkg -x clean.dat   # rebuild .dat from source first","handlingStrategy":"validation","validationCode":"# reject packages whose declared item sizes look corrupt before extracting\nicupkg -l \"$DAT\" | awk 'NR>1 && $2+0 > 1073741824 { print \"implausible item size:\",$0; exit 1 }'","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Sanity-check item lengths against the file size; a multi-GB item in a small .dat is corruption.","Regenerate .dat from clean source when lengths look wrong.","Raise available memory only after confirming the size is legitimate.","Validate with `icupkg -l` before extracting."],"tags":["icu","icupkg","memory","data-validation","build-tools"],"backgroundTag":null,"analyzedSha":"1b2de5e052fc0fb95fd7fb6846dcec4ade598e9e","analyzedAt":"2026-08-13T00:53:24.642Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}