{"record":{"id":"d3e807fde5dd2c1c","repo":"nodejs/node","slug":"icupkg-udata-openswapper-s-failed-s-n","errorCode":null,"errorMessage":"icupkg: udata_openSwapper(\\\"%s\\\") failed - %s\\n","messagePattern":"icupkg: udata_openSwapper\\(\\\\\"(.+?)\\\\\"\\) failed - (.+?)\\\\n","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"deps/icu-small/source/tools/toolutil/pkgitems.cpp","lineNumber":95,"sourceCode":"        return length;\n    }\n\n    void setItem(const Item *item, UDataSwapFn *swap) {\n        pItem=item;\n        int32_t infoLength, itemHeaderLength;\n        UErrorCode errorCode=U_ZERO_ERROR;\n        pInfo=::getDataInfo(pItem->data, pItem->length, infoLength, itemHeaderLength, &errorCode);\n        if(U_FAILURE(errorCode)) {\n            exit(errorCode); // should succeed because readFile() checks headers\n        }\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    }","sourceCodeStart":77,"sourceCodeEnd":113,"githubUrl":"https://github.com/nodejs/node/blob/1b2de5e052fc0fb95fd7fb6846dcec4ade598e9e/deps/icu-small/source/tools/toolutil/pkgitems.cpp#L77-L113","documentation":"When an item's endianness/charset differs from the host, pkgitems calls udata_openSwapper to byte-swap it; if that fails the item name + u_errorName are printed and exit(errorCode). The swap is needed because the .dat being extracted contains cross-endian/charset data.","triggerScenarios":"A .dat item whose data header declares an endianness/charsetFamily that udata_openSwapper rejects (invalid combination, or a corrupt header). The guard `if(U_FAILURE(errorCode))` after udata_openSwapper fires.","commonSituations":"Corrupt or hand-edited ICU .dat where the header's isBigEndian/charsetFamily bytes are invalid; a .dat produced by an incompatible/very old ICU version; truncation damaging the header.","solutions":["Regenerate the .dat from source data with a matching/current ICU build.","Verify the .dat header bytes (magic, endianness, charsetFamily) are valid before extracting.","Do not mix .dat files across incompatible ICU major versions; rebuild from source.","Run icupkg -l (list) to inspect the package integrity before operating on items."],"exampleFix":"# before: extracting from a corrupt/cross-endian .dat\nicupkg -x bad.dat\n# after\nicupkg -l good.dat            # confirm header is sane first\nicupkg -tb good.dat out.dat   # rebuild with host endianness","handlingStrategy":"validation","validationCode":"# inspect package integrity and header before extracting/swapping\nicupkg -l \"$DAT\" >/dev/null || { echo \"package header invalid\" >&2; exit 1; }\n# rebuild cross-endian .dat from source rather than trusting unknown files","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Do not trust .dat files of unknown provenance; rebuild from source data.","Use `icupkg -l` to validate a package before operating on its items.","Avoid mixing .dat files across incompatible ICU major versions.","If you must byte-swap, do it deliberately with `icupkg -tb/-tl` on a known-good package."],"tags":["icu","icupkg","endianness","data-validation","build-tools"],"backgroundTag":null,"analyzedSha":"1b2de5e052fc0fb95fd7fb6846dcec4ade598e9e","analyzedAt":"2026-08-13T00:53:24.642Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}