Bug 506659 - Support bypassing Linux's PATH_MAX, or providing an actionable error when it is reached; don't fail with a "not found" / "corrupt" error
Summary: Support bypassing Linux's PATH_MAX, or providing an actionable error when it ...
Status: REPORTED
Alias: None
Product: frameworks-kio
Classification: Frameworks and Libraries
Component: general (other bugs)
Version First Reported In: 6.15.0
Platform: Compiled Sources Other
: NOR minor
Target Milestone: ---
Assignee: KIO Bugs
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2025-07-06 00:12 UTC by Roke Julian Lockhart Beedell
Modified: 2025-08-11 17:42 UTC (History)
2 users (show)

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


Attachments
A Screenshot Of Dolphin On Windows Accessing A Path > PATH_MAX Via WSL2 (25.68 KB, image/png)
2025-07-06 00:12 UTC, Roke Julian Lockhart Beedell
Details
A CPP > PATH_MAX Path Generator And Viewer (21.40 KB, application/octet-stream)
2025-07-06 00:16 UTC, Roke Julian Lockhart Beedell
Details
A Screenshot Of An Erroneous Message Upon File Invocation Failure In Kate (460.85 KB, image/png)
2025-07-06 00:17 UTC, Roke Julian Lockhart Beedell
Details
A Demonstration That This Matters On Windows (Even Though It's Not MAX_PATH, It's PATH_MAX) (306.13 KB, image/png)
2025-07-06 00:29 UTC, Roke Julian Lockhart Beedell
Details
A Screenshot Of An Error Modal Demonstrating That This Breaks The Wastebin (52.19 KB, image/png)
2025-07-15 19:19 UTC, Roke Julian Lockhart Beedell
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Roke Julian Lockhart Beedell 2025-07-06 00:12:28 UTC
Created attachment 182992 [details]
A Screenshot Of Dolphin On Windows Accessing A Path > PATH_MAX Via WSL2

SUMMARY

On most Linux distributions, the PATH_MAX constant, as defined in `linux/limits.h`, defines the upper bound (typically 4096 bytes including the null terminator) for full path lengths when using certain legacy POSIX APIs, like `open()`, `stat()`, or `realpath()`. This limit, however, is not intrinsic to the file system, and can be circumvented using file-descriptor-relative system calls introduced in modern POSIX and Linux (such as `openat()` and `mkdirat()`), per https://bugreports.qt.io/browse/QTBUG-138251?focusedId=896968&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-896968.

However, descriptor exhaustion is real, so whether that's desirable is for you to decide. Though, I'll note that since KDE controls the DE, you'd be feasibly able to abstract this for all of your applications, and/or solely utilise the descriptors necessary. I've an implementation in Qt6 and CPP which confirms this.

In the event that it isn't desirable, a much better error message needs to be passed to the user, because Dolphin and KWrite's KParts, plus Gwenview, all return "file not found" or "corrupt", which is incorrect: the file exists. I've been advised at https://discuss.kde.org/t/what-component-do-all-kde-applications-call-that-prevents-them-opening-directories-and-files-whose-absolute-paths-are-path-max-s-value/36442/5?u=rokejulianlockhart that KDE utilises a different codepath to Qt for this, so you've an opportunity to improve upon this.

Per the included screenshot of Dolphin, this also affects Windows. Dolphin isn't unique in this, per https://github.com/files-community/Files/issues/17251#issue-3203800786. However, unlike on Linux, where PATH_MAX is essentially a hard limit for anyone not willing to interact with file descriptors, MAX_PATH on Windows (yes, it's a different variable) has long since been bypassed by first-party / Microsoft software (or the developers are implementing it, per https://github.com/microsoft/terminal/issues/19058#issuecomment-3029093394), and its maximum is > 32 000, per https://superuser.com/a/1908776/904401.

STEPS TO REPRODUCE

1.	A base directory is created, such as `$HOME/pathmax_test`.

2.	A directory name is prepared with a length of 255 characters (the maximum allowed by the NAME_MAX constant). For example, a string consisting of 255 'd' characters.

3.	A loop is used to repeatedly:

	- Create a new subdirectory with the prepared name using mkdirat(), which operates relative to a directory file descriptor.

	- Open the new subdirectory using openat(), obtaining a new directory file descriptor.

	- Close the previous directory descriptor and continue.

	Each level adds approximately 256 bytes to the total path length (255 from the directory name, plus 1 for the path separator).

4.	This process continues until the accumulated length of the path exceeds `PATH_MAX` (4096 bytes). Importantly, at no point is a full path constructed or passed to any system call; instead, each directory is accessed incrementally using file descriptors.

5.	Once the desired depth is reached, a file (say, named `deepfile.txt`) is created in the deepest directory using `openat()`, and test data is written to it using `write()`.

6.	Invoke `dolphin $HOME/pathmax_test`, and navigate as far as is possible.

OBSERVED RESULT

On a host Linux OS, it fails to render anything past `PATH_MAX`. On a client WSL2 hypervisor, it renders 2 levels of directories past `PATH_MAX` via the “Details” mode's tree view that it cannot enter, within which it considers a nested directory to be a file of unknown type.

EXPECTED RESULT

It should either be able to enter these directories, or it should clearly explain to the user why it is unable to.

SOFTWARE/OS VERSIONS

> ~~~
> Operating System: Fedora Linux 42
> KDE Plasma Version: 6.4.1
> KDE Frameworks Version: 6.15.0
> Qt Version: 6.9.1
> Kernel Version: 6.15.4-200.fc42.x86_64 (64-bit)
> Graphics Platform: Wayland
> Processors: 12 × AMD Ryzen 5 7600X 6-Core Processor
> Memory: 32 GiB of RAM (30.4 GiB usable)
> Graphics Processor 1: AMD Radeon RX 5700
> Graphics Processor 2: AMD Radeon Graphics
> Manufacturer: ASRock
> Product Name: X670E Taichi
> ~~~

Otherwise, my Windows environment is available at the relevant linked issues.
Comment 1 Roke Julian Lockhart Beedell 2025-07-06 00:16:29 UTC
Created attachment 182993 [details]
A CPP > PATH_MAX Path Generator And Viewer

See the cited QTBUG for instructions.
Comment 2 Roke Julian Lockhart Beedell 2025-07-06 00:17:24 UTC
Created attachment 182994 [details]
A Screenshot Of An Erroneous Message Upon File Invocation Failure In Kate
Comment 3 Roke Julian Lockhart Beedell 2025-07-06 00:29:35 UTC
Created attachment 182995 [details]
A Demonstration That This Matters On Windows (Even Though It's Not MAX_PATH, It's PATH_MAX)
Comment 4 Roke Julian Lockhart Beedell 2025-07-15 19:19:31 UTC
Created attachment 183254 [details]
A Screenshot Of An Error Modal Demonstrating That This Breaks The Wastebin

This also breaks `trash:/` (in Dolphin, but presumably across KIO), because I can't delete anything > PATH_MAX.
Comment 5 Roke Julian Lockhart Beedell 2025-08-11 17:42:36 UTC
(In reply to Roke Julian Lockhart Beedell from comment #4)

Of note is that `trash-cli-0.24.5.26-10.fc42.noarch`'s `trash-empty` command [^1] deletes them, so *this* can be feasibly solved for FreeDesktop-compliant wastebin implementations.

Relevantly, I've linked https://bugs.kde.org/show_bug.cgi?id=495214#c3.

[^1]: https://github.com/andreafrancia/trash-cli/blob/7bdaf964ea06f21d092d3f5b040c95e348edd20e/README.rst?plain=1#L17C5-L17C16:~:text=files%20and%20directories.-,trash%2Dempty,-empty%20the%20trashcan(s).