kovidgoyal/kitty · error
Out of memory reading PNG file at: %s
Error message
Out of memory reading PNG file at: %s
What it means
png_from_file_pointer could not allocate its initial 16 KiB read buffer via malloc, so reading the PNG file is aborted immediately with fclose and a false return. This is an environment-level memory exhaustion, not an image problem.
Source
Thrown at kitty/graphics.c:534
free(d.row_pointers);
free(d.error.buf);
return false;
}
*data = d.decompressed;
free(d.row_pointers);
free(d.error.buf);
*sz = d.sz;
*height = d.height;
*width = d.width;
return true;
}
bool
png_from_file_pointer(FILE *fp, const char *path_for_error_messages, uint8_t **data, unsigned int *width, unsigned int *height, size_t *sz) {
size_t capacity = 16 * 1024, pos = 0;
unsigned char *buf = malloc(capacity);
if (!buf) {
log_error("Out of memory reading PNG file at: %s", path_for_error_messages);
fclose(fp);
return false;
}
while (!feof(fp)) {
if (capacity - pos < 1024) {
capacity *= 2;
unsigned char *new_buf = realloc(buf, capacity);
if (!new_buf) {
free(buf);
log_error("Out of memory reading PNG file at: %s", path_for_error_messages);
fclose(fp);
return false;
}
buf = new_buf;
}
pos += fread(buf + pos, sizeof(char), capacity - pos, fp);
int saved_errno = errno;
if (ferror(fp) && saved_errno != EINTR) {View on GitHub (pinned to 6d5d0c4406)
Solutions
- Free system memory or raise the container/cgroup memory limit
- Check ulimit -v and raise or unset it: ulimit -v unlimited
- Temporarily remove background_image/window logo from kitty.conf to confirm the cause
- Investigate the memory hog with top/htop or systemd-cgtop
Defensive patterns
Strategy: fallback
Validate before calling
# shell: check headroom before launching kitty with a background image
free -m | awk '/Mem:/ {exit !($4 > 64)}' || sed -i '/^background_image/d' ~/.config/kitty/kitty.conf Try / catch
unsigned char *buf = malloc(16 * 1024);
if (!buf) { /* log and fall back to default background/icon */ } Prevention
- Set sane memory limits rather than hard caps on graphical sessions
- Monitor cgroup limits when running kitty in containers
- Keep background images small
When it happens
Trigger: System out of memory (or over commit limits hit) at the exact moment kitty reads a PNG icon/background image; malloc returning NULL under memory pressure, ulimit -v restrictions, or a 32-bit address space exhaustion.
Common situations: kitty started under a memory cgroup limit (containers, systemd user slices); ulimit -v set low in the shell; massive numbers of concurrent processes during login when background_image loads.
Related errors
- Failed to decode PNG image at: %s with error: %s
- Failed while reading from file: %s with error: %s
- The PNG image: %s could not be opened with error: %s
- Too many hyperlinks, discarding hyperlinks in scrollback
- Too many hyperlinks, discarding hyperlink: %s
AI-assisted analysis of kovidgoyal/kitty@6d5d0c4406 (2026-08-27).
Data as JSON: /api/errors/ffd871992c723349.
Report an issue: GitHub.