{"record":{"id":"d287b41a05de64fe","repo":"nodejs/node","slug":"could-not-read-dictionary-out-of-memory-n","errorCode":null,"errorMessage":"could not read dictionary: out of memory\\n","messagePattern":"could not read dictionary: out of memory\\\\n","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"deps/brotli/c/tools/brotli.c","lineNumber":918,"sourceCode":"  file_size_64 = FileSize(context->dictionary_path);\n  if (file_size_64 == -1) {\n    fprintf(stderr, \"could not get size of dictionary file [%s]\",\n            PrintablePath(context->dictionary_path));\n    fclose(f);\n    return BROTLI_FALSE;\n  }\n\n  if (file_size_64 > kMaxDictionarySize) {\n    fprintf(stderr, \"dictionary [%s] is larger than maximum allowed: %d\\n\",\n            PrintablePath(context->dictionary_path), kMaxDictionarySize);\n    fclose(f);\n    return BROTLI_FALSE;\n  }\n  context->dictionary_size = (size_t)file_size_64;\n\n  buffer = (uint8_t*)malloc(context->dictionary_size);\n  if (!buffer) {\n    fprintf(stderr, \"could not read dictionary: out of memory\\n\");\n    fclose(f);\n    return BROTLI_FALSE;\n  }\n  bytes_read = fread(buffer, sizeof(uint8_t), context->dictionary_size, f);\n  if (bytes_read != context->dictionary_size) {\n    free(buffer);\n    fprintf(stderr, \"failed to read dictionary [%s]: %s\\n\",\n            PrintablePath(context->dictionary_path), strerror(errno));\n    fclose(f);\n    return BROTLI_FALSE;\n  }\n  fclose(f);\n  context->dictionary = buffer;\n  if (command == COMMAND_COMPRESS) {\n    context->prepared_dictionary = BrotliEncoderPrepareDictionary(\n        BROTLI_SHARED_DICTIONARY_RAW, context->dictionary_size,\n        context->dictionary, BROTLI_MAX_QUALITY, NULL, NULL, NULL);\n    if (context->prepared_dictionary == NULL) {","sourceCodeStart":900,"sourceCodeEnd":936,"githubUrl":"https://github.com/nodejs/node/blob/1b2de5e052fc0fb95fd7fb6846dcec4ade598e9e/deps/brotli/c/tools/brotli.c#L900-L936","documentation":"`malloc` for the dictionary buffer returned NULL — the process could not allocate `context->dictionary_size` bytes to hold the dictionary contents in memory. The file was successfully sized but the heap is exhausted or the allocation exceeds platform limits.","triggerScenarios":"System memory is exhausted; the dictionary size is large enough to fail `malloc` on a 32-bit build (near or above 2 GB); container memory cgroup limit hit; ulimit on data segment (`ulimit -d`) too low.","commonSituations":"Running brotli in a memory-constrained container or embedded device; processing a dictionary that is near the brotli maximum on a system with limited RAM; many concurrent brotli processes competing for memory.","solutions":["Free memory or increase the container/cgroup memory limit.","Use a smaller dictionary file.","On 32-bit platforms, switch to a 64-bit build to enlarge the address space.","Check `ulimit -v` and `ulimit -d` and raise them if set low."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"#include <sys/sysinfo.h>\n#include <stdbool.h>\n\nbool enough_memory_for_dict(size_t dict_size) {\n    struct sysinfo si;\n    if (sysinfo(&si) != 0) return true; // can't check, proceed\n    // Need at least dict_size + overhead of free RAM\n    unsigned long long freeram = (unsigned long long)si.freeram * si.mem_unit;\n    return freeram > dict_size * 2; // 2x safety margin\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Monitor free memory before running brotli with large dictionaries.","Raise container/cgroup memory limits if hitting OOM.","Use smaller dictionaries on memory-constrained devices."],"tags":["memory","allocation","dictionary","brotli"],"backgroundTag":null,"analyzedSha":"1b2de5e052fc0fb95fd7fb6846dcec4ade598e9e","analyzedAt":"2026-08-13T00:53:24.642Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}