nodejs/node · error
could not get size of dictionary file [%s]
Error message
could not get size of dictionary file [%s]
What it means
`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.
Source
Thrown at deps/brotli/c/tools/brotli.c:902
static BROTLI_BOOL ReadDictionary(Context* context, Command command) {
static const int kMaxDictionarySize =
BROTLI_MAX_DISTANCE - BROTLI_MAX_BACKWARD_LIMIT(24);
FILE* f;
int64_t file_size_64;
uint8_t* buffer;
size_t bytes_read;
if (context->dictionary_path == NULL) return BROTLI_TRUE;
f = fopen(context->dictionary_path, "rb");
if (f == NULL) {
fprintf(stderr, "failed to open dictionary file [%s]: %s\n",
PrintablePath(context->dictionary_path), strerror(errno));
return BROTLI_FALSE;
}
file_size_64 = FileSize(context->dictionary_path);
if (file_size_64 == -1) {
fprintf(stderr, "could not get size of dictionary file [%s]",
PrintablePath(context->dictionary_path));
fclose(f);
return BROTLI_FALSE;
}
if (file_size_64 > kMaxDictionarySize) {
fprintf(stderr, "dictionary [%s] is larger than maximum allowed: %d\n",
PrintablePath(context->dictionary_path), kMaxDictionarySize);
fclose(f);
return BROTLI_FALSE;
}
context->dictionary_size = (size_t)file_size_64;
buffer = (uint8_t*)malloc(context->dictionary_size);
if (!buffer) {
fprintf(stderr, "could not read dictionary: out of memory\n");
fclose(f);
return BROTLI_FALSE;View on GitHub (pinned to 1b2de5e052)
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`.
Defensive patterns
Strategy: validation
Validate before calling
#include <sys/stat.h>
#include <stdbool.h>
bool dictionary_has_size(const char *path) {
struct stat st;
if (stat(path, &st) != 0) return false;
if (!S_ISREG(st.st_mode)) return false; // reject pipes, devices, dirs
return st.st_size > 0;
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: Pointing `--dictionary` at `/dev/stdin`, a named pipe, or a FUSE filesystem that does not implement seek; transient filesystem on a network mount.
Related errors
- failed to open dictionary file [%s]: %s\n
- failed to open input file [%s]: %s\n
- failed to open output file [%s]: %s\n
- failed to read dictionary [%s]: %s\n
- Error %s writing to the output path "%s"
AI-assisted analysis of nodejs/node@1b2de5e052 (2026-08-13).
Data as JSON: /api/errors/a69e5cfb1f79e50f.
Report an issue: GitHub.