Bug 499727 - KIO worker fails to create if the application name is longer than 66 characters
Summary: KIO worker fails to create if the application name is longer than 66 characters
Status: CONFIRMED
Alias: None
Product: frameworks-kio
Classification: Frameworks and Libraries
Component: Open/save dialogs (other bugs)
Version First Reported In: 6.10.0
Platform: Other Linux
: NOR normal
Target Milestone: ---
Assignee: KIO Bugs
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2025-02-09 18:56 UTC by Frank Fischer
Modified: 2025-02-10 15:06 UTC (History)
3 users (show)

See Also:
Latest Commit:
Version Fixed/Implemented In:
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Frank Fischer 2025-02-09 18:56:23 UTC
SUMMARY

If the kio file dialog is called via the xdg mechanism, e.g. by Qt's QFileDialog using native dialogs, and the application title is longer than 66 characters, the dialog fails with an error message.

STEPS TO REPRODUCE

Consider the following test program:

----
#include <QApplication>
#include <QFileDialog>

int main(int argc, char **argv)
{
    QApplication app(argc, argv);

    // this works
    // app.setApplicationName(QString(66, 'x'));

    // this fails
    app.setApplicationName(QString(67, 'x'));

    QFileDialog::getOpenFileName(nullptr, "open file");

    return app.exec();
}
----

OBSERVED RESULT

The application shows error message:

"Unable to create KIO worker. Can not create a socket for launching a KIO worker for protocol 'tags'."

EXPECTED RESULT

The file dialog works.

SOFTWARE/OS VERSIONS
Operating System: Void 
KDE Plasma Version: 6.2.5
KDE Frameworks Version: 6.10.0
Qt Version: 6.8.1
Kernel Version: 6.12.12_1 (64-bit)
Graphics Platform: Wayland
Processors: 12 × AMD Ryzen 5 PRO 7530U with Radeon Graphics
Memory: 14.4 GiB of RAM
Graphics Processor: AMD Radeon Graphics


ADDITIONAL INFORMATION
Comment 1 Nicolas Fella 2025-02-09 21:55:32 UTC
We are probably hitting a socket name limit here.

Out of curiosity, how did you find this?
Comment 2 Frank Fischer 2025-02-10 07:04:45 UTC
(In reply to Nicolas Fella from comment #1)
> We are probably hitting a socket name limit here.
> 
> Out of curiosity, how did you find this?

The problem occurred in the Lazarus IDE for free pascal if using the Qt5 or Qt6 backends. Lazarus (whether this is a good idea is a different question) changes the application title depending on the current project's path, i.e. by default it includes the full project path in the application title. And this title can become quite long. Someone in their forum found out that setting the application title to something different (i.e. shorter, not including the project path) seems to solve the problem (the application title is a user setting in Lazarus). I hit the same problem and realized that it occurred only for some projects, but not for all, and from there, only for some application titles but not for all. The rest of the story was just playing around and trying to find a small example to demonstrate the issue.

So currently, at least for Lazarus, this is a real problem not just an artificial one (luckily one with simple workaround for now).
Comment 3 Nicolas Fella 2025-02-10 11:12:56 UTC
I see. That looks like an unintended misuse of the Qt API. QCoreApplication::applicationName() isn't supposed to be used for user-visible application titles. That's what QGuiApplication::applicationDisplayName() is for.

Compare https://doc.qt.io/qt-6/qcoreapplication.html#applicationName-prop and https://doc.qt.io/qt-6/qguiapplication.html#applicationDisplayName-prop
Comment 4 Harald Sitter 2025-02-10 12:35:27 UTC
>    QTemporaryFile socketfile(prefix + QLatin1Char('/') + appName + QStringLiteral("XXXXXX.%1.kioworker.socket").arg(s_socketCounter.fetchAndAddAcquire(1)));

Meanwhile Qt internally builds on sockaddr_un which has a 108 character limit. We could probably just chop off appNames that are too long though that breaks the uniqueness of the path.

Maybe the better option would be to sha1 the entire app name and the counter, then use the hash as file name. It'd be of predictable length.
Comment 5 Frank Fischer 2025-02-10 15:06:52 UTC
(In reply to Nicolas Fella from comment #3)
> I see. That looks like an unintended misuse of the Qt API.
> QCoreApplication::applicationName() isn't supposed to be used for
> user-visible application titles. That's what
> QGuiApplication::applicationDisplayName() is for.
> 
> Compare https://doc.qt.io/qt-6/qcoreapplication.html#applicationName-prop
> and https://doc.qt.io/qt-6/qguiapplication.html#applicationDisplayName-prop

Thanks a lot, in particular for pointing out the applicationTitle issue. It has been changed in Lazarus and works fine. So at least the bug on the Lazarus side has been closed thanks to your hint.