{"record":{"id":"ffd871992c723349","repo":"kovidgoyal/kitty","slug":"out-of-memory-reading-png-file-at-s","errorCode":null,"errorMessage":"Out of memory reading PNG file at: %s","messagePattern":"Out of memory reading PNG file at: (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kitty/graphics.c","lineNumber":534,"sourceCode":"        free(d.row_pointers);\n        free(d.error.buf);\n        return false;\n    }\n    *data = d.decompressed;\n    free(d.row_pointers);\n    free(d.error.buf);\n    *sz = d.sz;\n    *height = d.height;\n    *width = d.width;\n    return true;\n}\n\nbool\npng_from_file_pointer(FILE *fp, const char *path_for_error_messages, uint8_t **data, unsigned int *width, unsigned int *height, size_t *sz) {\n    size_t capacity = 16 * 1024, pos = 0;\n    unsigned char *buf = malloc(capacity);\n    if (!buf) {\n        log_error(\"Out of memory reading PNG file at: %s\", path_for_error_messages);\n        fclose(fp);\n        return false;\n    }\n    while (!feof(fp)) {\n        if (capacity - pos < 1024) {\n            capacity *= 2;\n            unsigned char *new_buf = realloc(buf, capacity);\n            if (!new_buf) {\n                free(buf);\n                log_error(\"Out of memory reading PNG file at: %s\", path_for_error_messages);\n                fclose(fp);\n                return false;\n            }\n            buf = new_buf;\n        }\n        pos += fread(buf + pos, sizeof(char), capacity - pos, fp);\n        int saved_errno = errno;\n        if (ferror(fp) && saved_errno != EINTR) {","sourceCodeStart":516,"sourceCodeEnd":552,"githubUrl":"https://github.com/kovidgoyal/kitty/blob/6d5d0c440603ad9bdf6dcd599f73f6dde21acb44/kitty/graphics.c#L516-L552","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":null,"handlingStrategy":"fallback","validationCode":"# shell: check headroom before launching kitty with a background image\nfree -m | awk '/Mem:/ {exit !($4 > 64)}' || sed -i '/^background_image/d' ~/.config/kitty/kitty.conf","typeGuard":null,"tryCatchPattern":"unsigned char *buf = malloc(16 * 1024);\nif (!buf) { /* log and fall back to default background/icon */ }","preventionTips":["Set sane memory limits rather than hard caps on graphical sessions","Monitor cgroup limits when running kitty in containers","Keep background images small"],"tags":["kitty","png","out-of-memory","malloc","resource-limits"],"backgroundTag":"out-of-memory-allocation-failed","analyzedSha":"6d5d0c440603ad9bdf6dcd599f73f6dde21acb44","analyzedAt":"2026-08-27T14:20:20.142Z","schemaVersion":2},"datasetVersion":"2026-08-27T19:17:21.184Z"}