{"record":{"id":"6210f754771ca3b8","repo":"nodejs/node","slug":"u-index-outofbounds-error","errorCode":"U_INDEX_OUTOFBOUNDS_ERROR","errorMessage":"icupkg: too few bytes (%ld after header) for a .dat package\\n","messagePattern":"icupkg: too few bytes \\(%ld after header\\) for a \\.dat package\\\\n","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"deps/icu-small/source/tools/toolutil/package.cpp","lineNumber":528,"sourceCode":"    length-=headerLength;\n    if(length<4) {\n        /* itemCount does not fit */\n        offset=0x7fffffff;\n    } else {\n        itemCount = udata_readInt32(ds, *reinterpret_cast<const int32_t*>(inBytes));\n        setItemCapacity(itemCount); /* resize so there's space */\n        if(itemCount==0) {\n            offset=4;\n        } else if(length<(4+8*itemCount)) {\n            /* ToC table does not fit */\n            offset=0x7fffffff;\n        } else {\n            /* offset of the last item plus at least 20 bytes for its header */\n            offset = 20 + static_cast<int32_t>(ds->readUInt32(inEntries[itemCount - 1].dataOffset));\n        }\n    }\n    if(length<offset) {\n        fprintf(stderr, \"icupkg: too few bytes (%ld after header) for a .dat package\\n\",\n                        static_cast<long>(length));\n        exit(U_INDEX_OUTOFBOUNDS_ERROR);\n    }\n    /* do not modify the package length variable until the last item's length is set */\n\n    if(itemCount<=0) {\n        if(doAutoPrefix) {\n            fprintf(stderr, \"icupkg: --auto_toc_prefix[_with_type] but the input package is empty\\n\");\n            exit(U_INVALID_FORMAT_ERROR);\n        }\n    } else {\n        char prefix[MAX_PKG_NAME_LENGTH+4];\n        char *s, *inItemStrings;\n\n        if(itemCount>itemMax) {\n            fprintf(stderr, \"icupkg: too many items, maximum is %d\\n\", itemMax);\n            exit(U_BUFFER_OVERFLOW_ERROR);\n        }","sourceCodeStart":510,"sourceCodeEnd":546,"githubUrl":"https://github.com/nodejs/node/blob/1b2de5e052fc0fb95fd7fb6846dcec4ade598e9e/deps/icu-small/source/tools/toolutil/package.cpp#L510-L546","documentation":"Thrown by Package::readPackage() when the remaining data after the header (length - headerLength) is less than the computed minimum offset. The minimum offset is the larger of: the space needed for the item count int32, the full ToC table (4 + 8*itemCount bytes), or the last item's data offset plus 20 bytes for its header. This means the file is truncated relative to what its ToC claims.","triggerScenarios":"A .dat file whose header and ToC entries describe more data than the file actually contains. Specifically: length < 4 (no item count), or length < 4+8*itemCount (ToC table incomplete), or length < 20+lastItemDataOffset (last item header missing). The offset is set to 0x7fffffff (effectively infinite) when the ToC cannot fit, guaranteeing the check fails.","commonSituations":"Truncated .dat files from interrupted builds or incomplete downloads; corrupt ToC entries with inflated dataOffset values; manual editing of binary .dat files that changed the structure without updating offsets; filesystem corruption.","solutions":["Verify file integrity: compare file size against expected size from the build system.","Re-download or rebuild the .dat file.","Check the file is not truncated: ls -l and compare against a known-good copy.","If modifying .dat files, use icupkg itself rather than manual binary editing."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Verify file size is plausible for a .dat package\n#include <sys/stat.h>\n#include <fstream>\nbool isPlausibleDatSize(const char* filename) {\n    struct stat st;\n    if (stat(filename, &st) != 0) return false;\n    // A valid .dat must have at least a header + 4 bytes for item count\n    if (st.st_size < 32) return false;\n    // Read item count and check ToC plausibility\n    std::ifstream f(filename, std::ios::binary);\n    f.seekg(20); // approximate offset past header\n    int32_t itemCount = 0;\n    f.read(reinterpret_cast<char*>(&itemCount), 4);\n    // ToC must fit: 4 + 8*itemCount < remaining file\n    return itemCount >= 0 && (4 + 8 * static_cast<int64_t>(itemCount)) < st.st_size;\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Verify file integrity with checksums before processing.","Compare file size against known-good references.","Never manually edit .dat binary files — use icupkg operations only."],"tags":["icu","icupkg","truncated-file","bounds-check","toc","corrupt-file","index-outofbounds"],"backgroundTag":null,"analyzedSha":"1b2de5e052fc0fb95fd7fb6846dcec4ade598e9e","analyzedAt":"2026-08-13T00:53:24.642Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}