{"record":{"id":"a69e5cfb1f79e50f","repo":"nodejs/node","slug":"could-not-get-size-of-dictionary-file-s","errorCode":null,"errorMessage":"could not get size of dictionary file [%s]","messagePattern":"could not get size of dictionary file \\[(.+?)\\]","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"deps/brotli/c/tools/brotli.c","lineNumber":902,"sourceCode":"static BROTLI_BOOL ReadDictionary(Context* context, Command command) {\n  static const int kMaxDictionarySize =\n      BROTLI_MAX_DISTANCE - BROTLI_MAX_BACKWARD_LIMIT(24);\n  FILE* f;\n  int64_t file_size_64;\n  uint8_t* buffer;\n  size_t bytes_read;\n\n  if (context->dictionary_path == NULL) return BROTLI_TRUE;\n  f = fopen(context->dictionary_path, \"rb\");\n  if (f == NULL) {\n    fprintf(stderr, \"failed to open dictionary file [%s]: %s\\n\",\n            PrintablePath(context->dictionary_path), strerror(errno));\n    return BROTLI_FALSE;\n  }\n\n  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;","sourceCodeStart":884,"sourceCodeEnd":920,"githubUrl":"https://github.com/nodejs/node/blob/1b2de5e052fc0fb95fd7fb6846dcec4ade598e9e/deps/brotli/c/tools/brotli.c#L884-L920","documentation":"`FileSize()` returned -1 for the dictionary file, meaning `fopen` + `stat`/`fseek` to determine size failed even though the file was just opened successfully for reading. Note this message has no trailing newline — a minor formatting inconsistency in the tool.","triggerScenarios":"The file is a special file (FIFO, device, socket) where `stat` reports a size of 0 or fseek/ftell fails; the file was deleted between the successful open and the `FileSize` call (race condition); a procfs/sysfs pseudo-file.","commonSituations":"Pointing `--dictionary` at `/dev/stdin`, a named pipe, or a FUSE filesystem that does not implement seek; transient filesystem on a network mount.","solutions":["Ensure the dictionary path points to a regular file with a determinate size.","Materialize the dictionary to a plain file first: `cat pipe > /tmp/dict.bin && brotli --dictionary=/tmp/dict.bin input.txt`."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"#include <sys/stat.h>\n#include <stdbool.h>\n\nbool dictionary_has_size(const char *path) {\n    struct stat st;\n    if (stat(path, &st) != 0) return false;\n    if (!S_ISREG(st.st_mode)) return false; // reject pipes, devices, dirs\n    return st.st_size > 0;\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Ensure the dictionary path points to a regular file, not a pipe or device.","Pre-copy dictionary content to a plain file before passing to brotli.","Verify the file type with `file <dict_path>` before use."],"tags":["filesystem","io","dictionary","brotli"],"backgroundTag":null,"analyzedSha":"1b2de5e052fc0fb95fd7fb6846dcec4ade598e9e","analyzedAt":"2026-08-13T00:53:24.642Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}