Bug 474775

Summary: Endless copies of Kate spawned when opening files in a directory containing a .git folder (aka fork bomb)
Product: [Applications] kate Reporter: Sollace <sollacea>
Component: applicationAssignee: KWrite Developers <kwrite-bugs-null>
Status: RESOLVED FIXED    
Severity: normal CC: christoph, waqar.17a
Priority: NOR    
Version First Reported In: 23.08.1   
Target Milestone: ---   
Platform: Manjaro   
OS: Linux   
Latest Commit: Version Fixed In:
Sentry Crash Report:
Attachments: Needed folder structure to reproduce the bug (see next attachment for image)
Visualisation of folder structure

Description Sollace 2023-09-21 21:15:17 UTC
Created attachment 161790 [details]
Needed folder structure to reproduce the bug (see next attachment for image)

I've found a bug in Kate that can be used to turn it into a fork bomb of sorts. It's not particularly damaging since you can simply kill one of them to end the loop, however it can get extremely annoying and possible cause loss of work if you trigger it intentionally on a machine that's then left unattended for a while.


STEPS TO REPRODUCE
1. Open Kate
2. Settings > Configure Kate... > Behaviour
3. Turn on "Open each document in its own window"
4. Click "Okay" and close Kate
5. Create a new folder named "kate_bug" and in that folder new folder "A"
6. Inside folder "A" create a "a.txt" file and a ".git" folder
7. Go back up and create a copy of folder "A", name it "B"
8. Go back into folder "A" and open the text file in Kate (double-click or via open-with > Kate)
9. Switch to folder "B" and open the second text file using the same method

To aid with testing, I have also attached a zip file with the needed folder structure.



OBSERVED RESULT

Kate opens normally the first time, however when opening the second file Kate will continue to spawn new instances indefinitely until manual intervention.

EXPECTED RESULT

It shouldn't have done that.

SOFTWARE/OS VERSIONS
Windows: 
macOS: 
Linux/KDE Plasma: 
(available in About System)
KDE Plasma Version: 
KDE Frameworks Version: 
Qt Version: 

ADDITIONAL INFORMATION
Comment 1 Sollace 2023-09-21 21:16:06 UTC
Created attachment 161791 [details]
Visualisation of folder structure
Comment 2 Waqar Ahmed 2023-09-22 05:53:36 UTC
Seems like expected behaviour.

However I think the option `"Open each document in its own window"` should not be available in Kate. This option was added for KWrite and we left it in for Kate as well but I can see how it is mostly useless/destructive for Kate.
Comment 3 Christoph Cullmann 2023-09-22 08:09:29 UTC
(In reply to Waqar Ahmed from comment #2)
> Seems like expected behaviour.
> 
> However I think the option `"Open each document in its own window"` should
> not be available in Kate. This option was added for KWrite and we left it in
> for Kate as well but I can see how it is mostly useless/destructive for Kate.

Does that really spawn windows without end? Will need to try that.
Comment 4 Christoph Cullmann 2023-09-22 18:40:07 UTC
(In reply to Christoph Cullmann from comment #3)
> (In reply to Waqar Ahmed from comment #2)
> > Seems like expected behaviour.
> > 
> > However I think the option `"Open each document in its own window"` should
> > not be available in Kate. This option was added for KWrite and we left it in
> > for Kate as well but I can see how it is mostly useless/destructive for Kate.
> 
> Does that really spawn windows without end? Will need to try that.

Ok, yes, that is fun :)
Comment 5 Christoph Cullmann 2023-09-22 20:14:11 UTC
I think we should not start to create windows for documents that are already open, we should just activate the matching one.
That will avoid that issue and make the SDI mode more usable.
Comment 6 Bug Janitor Service 2023-09-22 20:28:26 UTC
A possibly relevant merge request was started @ https://invent.kde.org/utilities/kate/-/merge_requests/1307
Comment 7 Christoph Cullmann 2023-09-22 20:29:06 UTC
I think one can trigger that even in KWrite, should be fixed with that minimal invasive patch.
Comment 8 Christoph Cullmann 2023-09-25 16:40:14 UTC
Git commit 311fac70f5f1517abf7285a97fae23a0356e94f9 by Christoph Cullmann.
Committed on 25/09/2023 at 18:35.
Pushed by cullmann into branch 'master'.

try to re-use open views to avoid massive windows spawning

even without the project plugin you could trigger that in KWrite

M  +3    -2    apps/lib/kateviewmanager.cpp

https://invent.kde.org/utilities/kate/-/commit/311fac70f5f1517abf7285a97fae23a0356e94f9