https://bugs.kde.org/show_bug.cgi?id=506659

            Bug ID: 506659
           Summary: Support bypassing Linux's PATH_MAX, or providing an
                    actionable error when it is reached; don't fail with a
                    "not found" / "corrupt" error
    Classification: Frameworks and Libraries
           Product: frameworks-kio
      Version First 6.15.0
       Reported In:
          Platform: Compiled Sources
                OS: Other
            Status: REPORTED
          Severity: minor
          Priority: NOR
         Component: general
          Assignee: kio-bugs-n...@kde.org
          Reporter: 4wy78...@rokejulianlockhart.addy.io
                CC: kdelibs-b...@kde.org
  Target Milestone: ---

Created attachment 182992
  --> https://bugs.kde.org/attachment.cgi?id=182992&action=edit
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.

-- 
You are receiving this mail because:
You are watching all bug changes.

Reply via email to