Bug 500892

Summary: Kate allocates all system memory until system crash or OOM-killed in certain situations involving symlinks
Product: [Applications] kate Reporter: thatkles
Component: generalAssignee: KWrite Developers <kwrite-bugs-null>
Status: RESOLVED FIXED    
Severity: normal CC: christoph, nicolas.fella
Priority: NOR    
Version First Reported In: unspecified   
Target Milestone: ---   
Platform: Arch Linux   
OS: Linux   
Latest Commit: Version Fixed/Implemented In:
Sentry Crash Report:

Description thatkles 2025-03-01 12:10:29 UTC
SUMMARY

When using the Open Folder (Ctrl+T) mode, Kate appears to attempt to load large directories multiple times for each symlink that points to it, potentially consuming all available system memory until system crash or OOM-killed. 

On my setup, I have my old Windows SSD mounted on at /mnt/c/. This is a large directory, and if I target it with Kate's Open Folder feature, Kate allocates approximately 2 GB of memory to fully load it (this seems very excessive on its own!). However, I have programs like Wine, Proton, and Lutris installed, and each of these can sometimes create multiple WINEPREFIX directories, which each contain a Z: symlink, which points to my Linux drive, which contains /mnt/c/. For each of these WINEPREFIX directories, I believe it's trying to load the entire filesystem, /mnt/c/ and all, over and over again. Given that Proton on Steam alone currently has 26 of these WINEPREFIX directories, this means that Kate will attempt to fully load these directories over and over again, crashing any system that has under 50 or so free gigabytes of free memory (which will be most of them).

Now that I think about it, the /mnt/c/ situation may not even be necessary. If a symlink points to the system's root directory, it may try to recursively reload the entire filesystem again every time it reaches that symlink. However, given how common Wine is, I feel like this problem would have been encountered long ago if it were that simple. In any case, I feel like there should be some kind of brake in Kate that stops it from allocating an unreasonable amount of memory regardless of the filesystem setup.

STEPS TO REPRODUCE
1. Open a WINEPREFIX directory (specifically, the dosdevices directory) while a large drive is mounted to the filesystem. 
2. Wait until Kate allocates all remaining system memory (or a very large portion of it), crashing the system or being OOM-killed.

OBSERVED RESULT

The system crashes or Kate is OOM-killed.

EXPECTED RESULT

The directory listing is displayed in the folder panel.

SOFTWARE/OS VERSIONS
Operating System: EndeavourOS 
KDE Plasma Version: 6.3.2
KDE Frameworks Version: 6.11.0
Qt Version: 6.8.2
Comment 1 thatkles 2025-03-01 12:14:36 UTC
(Oops, sorry about the importance - I meant to select "grave," but it appears I selected "critical" instead, and it doesn't appear that I can change it.)
Comment 2 Bug Janitor Service 2025-03-01 19:51:14 UTC
A possibly relevant merge request was started @ https://invent.kde.org/utilities/kate/-/merge_requests/1746
Comment 3 Waqar Ahmed 2025-03-03 15:53:38 UTC
Git commit bc3c9b0b9d771b7525b3545f163c8af7df3ac1fd by Waqar Ahmed, on behalf of Christoph Cullmann.
Committed on 03/03/2025 at 10:26.
Pushed by cullmann into branch 'master'.

disable following of symlinks per default for directory mode

add "symlinks" attribute to allow that again

M  +3    -0    addons/project/kateproject.example
M  +8    -11   addons/project/kateprojectworker.cpp
M  +1    -1    addons/project/kateprojectworker.h

https://invent.kde.org/utilities/kate/-/commit/bc3c9b0b9d771b7525b3545f163c8af7df3ac1fd