Bug 494335

Summary: Having xdg-open or kde-open as a preferred service causes infinite loop and CPU spike
Product: [Frameworks and Libraries] frameworks-kservice Reporter: Akseli Lahtinen <akselmo>
Component: generalAssignee: KIO Bugs <kio-bugs-null>
Status: RESOLVED FIXED    
Severity: normal CC: kdelibs-bugs, nate
Priority: NOR    
Version: unspecified   
Target Milestone: ---   
Platform: Other   
OS: Linux   
Latest Commit: Version Fixed In: 6.8
Sentry Crash Report:

Description Akseli Lahtinen 2024-10-09 08:43:31 UTC
SUMMARY

There are some applications that have buggy file-opening or handling, and they manage to set the mimetype to open with "xdg-open" or "kde-open."

This causes the file to open inside a recursive loop, eating CPU and causing sad times.

The application that was reported to me is called `p4v` and apparently that has a bug like this. I haven't been
able to test it in the application itself since it is proprietary + costs big money.

It is an application side bug, but we should still handle these situations gracefully to avoid users PC to be in weird place.

STEPS TO REPRODUCE
1. Create empty file
2. Set that file to always open with `xdg-open` or `kde-open`
3. Try opening the file with `xdg-open` or `kde-open` inside terminal
4. Try opening the file from Dolphin by clicking on it

OBSERVED RESULT
CPU spiking to 100%, user has to run `killall kde-open` in terminal to get rid of it

EXPECTED RESULT
We would get the open-with dialog instead

SOFTWARE/OS VERSIONS
Operating System: Fedora Linux 40
KDE Plasma Version: 6.2.80
KDE Frameworks Version: 6.7.0
Qt Version: 6.7.2
Kernel Version: 6.10.12-200.fc40.x86_64 (64-bit)
Graphics Platform: Wayland
Processors: 12 × AMD Ryzen 5 3600 6-Core Processor
Memory: 15,5 GiB of RAM
Graphics Processor: AMD Radeon RX 6600
Comment 1 Akseli Lahtinen 2024-10-09 08:45:16 UTC
I've also made a relevant merge request: https://invent.kde.org/frameworks/kservice/-/merge_requests/186
Comment 2 Akseli Lahtinen 2024-10-14 08:37:49 UTC
Git commit 4fbda144ab4b77a2d99eb0dca1ff3cf75957cf55 by Akseli Lahtinen.
Committed on 14/10/2024 at 08:37.
Pushed by akselmo into branch 'master'.

openurljob.cpp: Avoid opening files in endless loop if mimetype is set to open with xdg-open

Some applications set their file mimetypes to open with "xdg-open" which then
causes it open in "kde-open", which then ends up calling itself
constantly and endlessly, spiking CPU.

Instead, catch that early on and show the "Open with dialog", so
we handle the file like it has no set default application.

M  +7    -0    src/gui/openurljob.cpp

https://invent.kde.org/frameworks/kio/-/commit/4fbda144ab4b77a2d99eb0dca1ff3cf75957cf55