{"record":{"id":"12ef49bb9db7c125","repo":"nodejs/node","slug":"u-invalid-format-error-12ef49","errorCode":"U_INVALID_FORMAT_ERROR","errorMessage":"icupkg: not an ICU data file: \\\"%s\\\"\\n","messagePattern":"icupkg: not an ICU data file: \\\\\"(.+?)\\\\\"\\\\n","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"deps/icu-small/source/tools/toolutil/package.cpp","lineNumber":356,"sourceCode":"    /* read the file */\n    if (fileLength != static_cast<int32_t>(fread(data.getAlias(), 1, fileLength, file))) {\n        fprintf(stderr, \"icupkg: error reading \\\"%s\\\"\\n\", filename);\n        fclose(file);\n        exit(U_FILE_ACCESS_ERROR);\n    }\n\n    /* pad the file to a multiple of 16 using the usual padding byte */\n    if(fileLength<length) {\n        memset(data.getAlias()+fileLength, 0xaa, length-fileLength);\n    }\n\n    fclose(file);\n\n    // minimum check for ICU-format data\n    errorCode=U_ZERO_ERROR;\n    typeEnum=getTypeEnumForInputData(data.getAlias(), length, &errorCode);\n    if(typeEnum<0 || U_FAILURE(errorCode)) {\n        fprintf(stderr, \"icupkg: not an ICU data file: \\\"%s\\\"\\n\", filename);\n#if !UCONFIG_NO_LEGACY_CONVERSION\n        exit(U_INVALID_FORMAT_ERROR);\n#else\n        fprintf(stderr, \"U_INVALID_FORMAT_ERROR occurred but UCONFIG_NO_LEGACY_CONVERSION is on so this is expected.\\n\");\n        exit(0);\n#endif\n    }\n    type=makeTypeLetter(typeEnum);\n\n    return data.orphan();\n}\n\n// .dat package file representation ---------------------------------------- ***\n\nU_CDECL_BEGIN\n\nstatic int32_t U_CALLCONV\ncompareItems(const void * /*context*/, const void *left, const void *right) {","sourceCodeStart":338,"sourceCodeEnd":374,"githubUrl":"https://github.com/nodejs/node/blob/1b2de5e052fc0fb95fd7fb6846dcec4ade598e9e/deps/icu-small/source/tools/toolutil/package.cpp#L338-L374","documentation":"Thrown by readFile() when getTypeEnumForInputData() returns a negative value or sets a failure UErrorCode after inspecting the file's header. This means the data does not have a valid ICU data header (magic bytes, UDataInfo structure) for any recognized charset/endian combination.","triggerScenarios":"Passing a non-ICU binary file as input to icupkg, or a corrupted/truncated ICU data file whose header bytes are invalid. getTypeEnumForInputData() inspects the data header to determine charset family and endianness; if it cannot, the file is rejected as not an ICU data file.","commonSituations":"Wrong file passed to icupkg (e.g. a .so, .exe, or arbitrary binary instead of an ICU .dat or item file); a .dat file that was downloaded incorrectly (HTML error page saved as .dat); a file corrupted by transfer (FTP text mode, encoding conversion); a file from a future or incompatible ICU version with a different header format.","solutions":["Verify the file is actually an ICU data file: hexdump -C <file> | head and look for the ICU magic header.","Re-download or rebuild the data file from a trusted source.","Ensure binary-safe transfer: use scp or rsync, not FTP text mode.","Check the ICU version compatibility between the data file and the icupkg tool version."],"exampleFix":"// verify the file header\n// before: random file passed as .dat\nicupkg unknown_file.dat\n// after: use the correct ICU data file\nicupkg icudt62l.dat","handlingStrategy":"validation","validationCode":"// Check for ICU data header magic bytes before processing\n#include <fstream>\n#include <cstring>\nbool hasValidICUHeader(const char* filename) {\n    std::ifstream f(filename, std::ios::binary);\n    if (!f) return false;\n    char buf[32];\n    f.read(buf, sizeof(buf));\n    if (f.gcount() < 16) return false;\n    // Check for ICU data header magic (0xda 0x27 or similar in header)\n    uint16_t magic = *reinterpret_cast<uint16_t*>(buf + 0);\n    return magic == 0xda; // ICU data magic\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Verify the file source — only use ICU data files from trusted builds.","Check file type with the 'file' command before passing to icupkg.","Use binary-safe transfer methods (scp, rsync) to avoid corruption."],"tags":["icu","icupkg","invalid-format","corrupt-file","data-header","binary"],"backgroundTag":null,"analyzedSha":"1b2de5e052fc0fb95fd7fb6846dcec4ade598e9e","analyzedAt":"2026-08-13T00:53:24.642Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}