{"record":{"id":"e0f75ec90692b4ef","repo":"nodejs/node","slug":"u-internal-program-error","errorCode":"U_INTERNAL_PROGRAM_ERROR","errorMessage":"genrb error: wrote %u bytes but counted %u","messagePattern":"genrb error: wrote %u bytes but counted %u","errorType":"console","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"deps/icu-small/source/tools/genrb/reslist.cpp","lineNumber":1088,"sourceCode":"\n    /* write the indexes[] */\n    udata_writeBlock(mem, indexes, fIndexLength*4);\n\n    /* write the table key strings */\n    udata_writeBlock(mem, fKeys+fKeysBottom,\n                          fKeysTop-fKeysBottom);\n\n    /* write the v2 UTF-16 strings, URES_TABLE16 and URES_ARRAY16 */\n    udata_writeBlock(mem, f16BitUnits.getBuffer(), f16BitUnits.length()*2);\n\n    /* write all of the bundle contents: the root item and its children */\n    byteOffset = fKeysTop + f16BitUnits.length() * 2;\n    fRoot->write(mem, &byteOffset);\n    assert(byteOffset == top);\n\n    size = udata_finish(mem, &errorCode);\n    if(top != size) {\n        fprintf(stderr, \"genrb error: wrote %u bytes but counted %u\\n\",\n                static_cast<int>(size), static_cast<int>(top));\n        errorCode = U_INTERNAL_PROGRAM_ERROR;\n    }\n}\n\n/* Opening Functions */\n\nTableResource* table_open(struct SRBRoot *bundle, const char *tag, const struct UString* comment, UErrorCode *status) {\n    LocalPointer<TableResource> res(new TableResource(bundle, tag, comment, *status), *status);\n    return U_SUCCESS(*status) ? res.orphan() : nullptr;\n}\n\nArrayResource* array_open(struct SRBRoot *bundle, const char *tag, const struct UString* comment, UErrorCode *status) {\n    LocalPointer<ArrayResource> res(new ArrayResource(bundle, tag, comment, *status), *status);\n    return U_SUCCESS(*status) ? res.orphan() : nullptr;\n}\n\nstruct SResource *string_open(struct SRBRoot *bundle, const char *tag, const char16_t *value, int32_t len, const struct UString* comment, UErrorCode *status) {","sourceCodeStart":1070,"sourceCodeEnd":1106,"githubUrl":"https://github.com/nodejs/node/blob/1b2de5e052fc0fb95fd7fb6846dcec4ade598e9e/deps/icu-small/source/tools/genrb/reslist.cpp#L1070-L1106","documentation":"After writing all bundle contents to a UDataMemory block, genrb calls udata_finish() to get the actual bytes written and compares it to the pre-computed 'top' offset. If these do not match, it indicates an internal bug in genrb's size accounting: the code counted a different number of bytes than it actually wrote. Sets U_INTERNAL_PROGRAM_ERROR — this is never a user input error.","triggerScenarios":"This error is produced by a bug in genrb's own byte-counting logic. The fRoot->write() function, key writing, or 16-bit unit writing computed offsets that don't match what udata_write actually produced. The assert(byteOffset == top) on the preceding line either passed (in release builds) or would have caught a different class of the same bug.","commonSituations":"Using a version of ICU with a known genrb size-accounting bug; building resource bundles with unusual structures (deeply nested tables, very large arrays, mixed 16-bit and 32-bit resources) that expose an edge case in the size calculator; building with compiler optimizations that expose undefined behavior in genrb's pointer arithmetic.","solutions":["Report this as an ICU bug — U_INTERNAL_PROGRAM_ERROR in this path is always a genrb defect, not user error","Try a different ICU version (upgrade or downgrade) to see if the bug is fixed","Simplify the resource bundle structure to avoid the triggering edge case (reduce nesting depth, split large arrays)","Build genrb with debug assertions enabled (NDEBUG undefined) so the assert catches the discrepancy earlier","If possible, restructure the resource bundle to avoid mixed 16-bit/32-bit resource types that may trigger the counting bug"],"exampleFix":null,"handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":["This is an internal genrb bug — report it to the ICU project with the resource bundle that triggers it","Keep multiple ICU versions available to test whether a different version avoids the bug","Build genrb with assertions enabled (without -DNDEBUG) during development to catch size-accounting bugs earlier","Minimize unusual resource bundle structures (extreme nesting, very large arrays) that may trigger edge cases"],"tags":["icu","genrb","internal-error","bug","size-mismatch"],"backgroundTag":null,"analyzedSha":"1b2de5e052fc0fb95fd7fb6846dcec4ade598e9e","analyzedAt":"2026-08-13T00:53:24.642Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}