nodejs/node · critical

U_MEMORY_ALLOCATION_ERROR

U_MEMORY_ALLOCATION_ERROR

Error message

icupkg: malloc error allocating %d bytes.\n

What it means

Thrown by readFile() when uprv_malloc() returns NULL while allocating a buffer for reading a data file. The allocation size is the file length padded up to a multiple of 16 bytes. This indicates the system cannot satisfy the memory request.

Source

Thrown at deps/icu-small/source/tools/toolutil/package.cpp:334

    if(file==nullptr) {
        fprintf(stderr, "icupkg: unable to open input file \"%s\"\n", filename);
        exit(U_FILE_ACCESS_ERROR);
    }

    /* get the file length */
    fileLength=getFileLength(file);
    if(ferror(file) || fileLength<=0) {
        fprintf(stderr, "icupkg: empty input file \"%s\"\n", filename);
        fclose(file);
        exit(U_FILE_ACCESS_ERROR);
    }

    /* allocate the buffer, pad to multiple of 16 */
    length=(fileLength+0xf)&~0xf;
    icu::LocalMemory<uint8_t> data(static_cast<uint8_t*>(uprv_malloc(length)));
    if(data.isNull()) {
        fclose(file);
        fprintf(stderr, "icupkg: malloc error allocating %d bytes.\n", static_cast<int>(length));
        exit(U_MEMORY_ALLOCATION_ERROR);
    }

    /* read the file */
    if (fileLength != static_cast<int32_t>(fread(data.getAlias(), 1, fileLength, file))) {
        fprintf(stderr, "icupkg: error reading \"%s\"\n", filename);
        fclose(file);
        exit(U_FILE_ACCESS_ERROR);
    }

    /* pad the file to a multiple of 16 using the usual padding byte */
    if(fileLength<length) {
        memset(data.getAlias()+fileLength, 0xaa, length-fileLength);
    }

    fclose(file);

    // minimum check for ICU-format data

View on GitHub (pinned to 1b2de5e052)

Solutions

  1. Check available memory: free -h and ulimit -v.
  2. If running in a container, increase the memory limit.
  3. Reduce the data file size by trimming unnecessary locales with icupkg -r before processing.
  4. Build with a 64-bit toolchain if currently 32-bit.
Defensive patterns

Strategy: validation

Validate before calling

// Check available memory and file size before processing
#include <sys/stat.h>
#include <sys/resource.h>
bool canAllocateForFile(const char* filename) {
    struct stat st;
    if (stat(filename, &st) != 0) return false;
    size_t needed = (st.st_size + 0xf) & ~0xf; // pad to 16
    struct rlimit rl;
    if (getrlimit(RLIMIT_AS, &rl) == 0 && rl.rlim_cur != RLIM_INFINITY) {
        return needed < rl.rlim_cur / 4; // conservative heuristic
    }
    return true;
}

Prevention

When it happens

Trigger: Reading a data file whose padded length causes uprv_malloc() to fail. This can happen with very large data files, or when system memory is exhausted. The padded length is (fileLength + 0xf) & ~0xf.

Common situations: Very large ICU data files that exceed available virtual memory; process memory limits (ulimit -v) in CI environments; containers with low memory cgroup limits; 32-bit processes with limited address space; memory fragmentation after many allocations.

Related errors


AI-assisted analysis of nodejs/node@1b2de5e052 (2026-08-13). Data as JSON: /api/errors/f9bbf2c7e9b94178. Report an issue: GitHub.