https://bugs.kde.org/show_bug.cgi?id=525771

            Bug ID: 525771
           Summary: kateprojectplugin: unbounded memory allocation and OOM
                    crash when opening files in large Git repos
    Classification: Applications
           Product: kate
      Version First 26.08.1
       Reported In:
          Platform: CachyOS
                OS: Linux
            Status: REPORTED
          Severity: crash
          Priority: NOR
         Component: application
          Assignee: [email protected]
          Reporter: [email protected]
  Target Milestone: ---

Created attachment 196181
  --> https://bugs.kde.org/attachment.cgi?id=196181&action=edit
KDE System Monitor showing Kate at 9.8 GiB memory consumption and 73.6% CPU
right before the kernel OOM termination.

When opening any individual text file (e.g. LICENSE or README.md) located
inside a Git repository with a large Git index (such as cdnjs with ~26M tracked
files,
  even under git sparse-checkout where files are not checked out on disk),
Kate's project plugin automatically attempts to index the entire repository
into memory. 

    This triggers unbounded heap allocation, rapidly reaching 10–15 GiB of RAM
and swap within 2–3 minutes, until the desktop session freezes and the Linux
kernel  
  OOM killer terminates Kate with SIGKILL.

    STEPS TO REPRODUCE
    1. Clone or initialize a repository with a large Git index (e.g. cdnjs: git
clone --filter=blob:none --sparse https://github.com/cdnjs/cdnjs where sparse
rules 
  exclude !/ajax/*).
    2. Open a single small text file inside the repository root using Kate:
       kate cdnjs/LICENSE
    3. Observe memory usage in System Monitor.

    OBSERVED RESULT
    In addons/project/kateprojectworker.cpp:
    1. filesFromGit() executes:
       git ls-files -z --recurse-submodules --deduplicate .
       This outputs all 26,244,085 indexed files (~2.5 GiB of raw stdout)
because it does not filter files marked with the skip-worktree bit from sparse
checkout.  
    2. gitFiles() reads the entire stream into a single QByteArray via
readAllStandardOutput().
    3. QtConcurrent::blockingMap() spawns worker threads that call QFileInfo
and allocate a new KateProjectItem for every single file.
    4. Total virtual memory exceeds 15 GiB, exhausting system RAM and swap
until the kernel OOM killer sends SIGKILL:
       Out of memory: Killed process 99806 (kate) total-vm:15566468kB,
anon-rss:5598956kB

    EXPECTED RESULT
    1. Kate should enforce a safety threshold (e.g. max 50,000 files) and abort
indexing with a warning infobar rather than exhausting all system memory.       
    2. Kate should respect Git sparse checkout by ignoring files marked with
the skip-worktree bit.
    3. Tree view items should be loaded lazily on directory expansion rather
than allocating millions of QStandardItem objects up front.

    SOFTWARE/OS VERSIONS
    Operating System: CachyOS Linux (Kernel: 7.2.4-3-cachyos, 64-bit, Wayland)
    KDE Plasma Version: 6.7.5
    KDE Frameworks Version: 6.30.0
    Qt Version: 6.11.2

    ADDITIONAL INFORMATION
    Attached screenshot from KDE System Monitor showing Kate at 9.8 GiB memory
consumption and 73.6% CPU right before the kernel OOM termination.

-- 
You are receiving this mail because:
You are watching all bug changes.

Reply via email to