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

  1. Free system memory or raise the container/cgroup memory limit
  2. Check ulimit -v and raise or unset it: ulimit -v unlimited
  3. Temporarily remove background_image/window logo from kitty.conf to confirm the cause
  4. 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

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


AI-assisted analysis of kovidgoyal/kitty@6d5d0c4406 (2026-08-27). Data as JSON: /api/errors/ffd871992c723349. Report an issue: GitHub.