Bug 497195 - Symlinked files are truncated when accessed through SFTP (sftp_aio)
Summary: Symlinked files are truncated when accessed through SFTP (sftp_aio)
Status: RESOLVED FIXED
Alias: None
Product: kio-extras
Classification: Frameworks and Libraries
Component: SFTP (show other bugs)
Version: 24.08.3
Platform: Other Other
: NOR normal
Target Milestone: ---
Assignee: Plasma Bugs List
URL:
Keywords:
: 501701 (view as bug list)
Depends on:
Blocks:
 
Reported: 2024-12-08 10:05 UTC by Kishore Gopalakrishnan
Modified: 2025-03-28 06:34 UTC (History)
2 users (show)

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


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Kishore Gopalakrishnan 2024-12-08 10:05:34 UTC
SUMMARY
A symlink to a text file (both located in a folder accessed via SFTP) only shows a truncated version of that text file when accessed through SFTP.

STEPS TO REPRODUCE
1. On a remote computer (which you have ssh access to), make a symlink to a long text file (size needs to be more than a few bytes; I used a 1.7KB text file as an example)
2. Open the symlink location in Dolphin on your local computer (In the address bar, type sftp://USERNAME@SERVER:22/PATH_TO_FILE/ )
3. Open the symlink with Kate
4. Copy the symlink to a local folder using Dolphin

OBSERVED RESULTS
3. Kate only shows the first few characters of the file.
4. The local copy created by Dolphin only contains the first few characters of the file.

EXPECTED RESULTS
3. Kate should show the entire file
4. Dolphin should copy the entire file

SOFTWARE VERSIONS
kate 24.08.3
kio-extras 24.08.3
libssh 0.11.1
libssh2 1.11.0
openssh 9.9p1
sshfs 3.7.3
Operating System: Arch Linux 
KDE Plasma Version: 6.2.4
KDE Frameworks Version: 6.8.0
Qt Version: 6.8.1
Kernel Version: 6.12.3-arch1-1 (64-bit)

ADDITIONAL INFORMATION
A. If I do the same on a local filesystem, the entire file is shown when opening the symlink.
B. Permissions in a case where this bug can be reproduced (I opened link.txt, which I earlier created using `ln -s`)
```
$ ls -lh
total 4.0K
lrwxrwxrwx 1 ckishore expert   13 Dec  8 15:20 link.txt -> test_file.txt
-rw-r--r-- 1 ckishore expert 1.8K Dec  8 15:20 test_file.txt
```
C. Note that the size of the symlink is 13B; in this case, exactly the first 13 characters of the text file were shown, suggesting that kio_sftp is wrongly truncating the file based on the symlink size.
D. On the remote computer, using `cat link.txt` gives me the entire text file, suggesting there is no issue on the remote end.
Comment 1 John Kizer 2024-12-19 06:17:56 UTC
Hi - thanks for the detailed report! I'm unable to reproduce it on my system below, though - has this situation ever worked correctly on your system (if you had ever tried it before?), even if under previous software versions?

Operating System: Fedora Linux 41
KDE Plasma Version: 6.2.4
KDE Frameworks Version: 6.9.0
Qt Version: 6.8.1
Kernel Version: 6.12.4-200.fc41.x86_64 (64-bit)
Comment 2 Kishore Gopalakrishnan 2025-01-02 05:02:53 UTC
(In reply to John Kizer from comment #1)
> Hi - thanks for the detailed report! I'm unable to reproduce it on my system
> below, though - has this situation ever worked correctly on your system (if
> you had ever tried it before?), even if under previous software versions?
> 
> Operating System: Fedora Linux 41
> KDE Plasma Version: 6.2.4
> KDE Frameworks Version: 6.9.0
> Qt Version: 6.8.1
> Kernel Version: 6.12.4-200.fc41.x86_64 (64-bit)

It used to work correctly on my system. Unfortunately, I'm not sure exactly how long ago it stopped working, since I don't access symlinks on remote systems that often.

Fedora 41 has libssh 0.10.6, while I have 0.11.1 on Arch Linux. I suspect this could be related to the new feature mentioned in https://bugs.kde.org/show_bug.cgi?id=296526#c42 . One way to confirm this would be for me to build a version of kio-sftp with that feature patched out, but that will have to wait until the weekend at least.
Comment 3 Kishore Gopalakrishnan 2025-01-19 10:31:22 UTC
(In reply to Kishore Gopalakrishnan from comment #2)
> [snip]
> 
> Fedora 41 has libssh 0.10.6, while I have 0.11.1 on Arch Linux. I suspect
> this could be related to the new feature mentioned in
> https://bugs.kde.org/show_bug.cgi?id=296526#c42 . 
>
> [snip]

I have confirmed this. The bug is not reproducible if I remove the `HAVE_SFTP_AIO` option from kio-extras/sftp/CMakeLists.txt (forcing kio-sftp to always use the old code path).
Comment 4 Kishore Gopalakrishnan 2025-01-19 10:53:43 UTC
The issue is fixed by replacing all uses of `sftp_lstat` by `sftp_stat` in kio_sftp.cpp
Comment 5 Bug Janitor Service 2025-01-19 11:57:49 UTC
A possibly relevant merge request was started @ https://invent.kde.org/network/kio-extras/-/merge_requests/403
Comment 6 Méven 2025-02-23 10:11:51 UTC
Git commit 5fd0630699e5d0d150709bf0cd5e935d725137f0 by Méven Car, on behalf of Kishore Gopalakrishnan.
Committed on 23/02/2025 at 10:07.
Pushed by meven into branch 'master'.

sftp: use stat instead of lstat

Using lstat leads to symlinks being truncated (since the file gets
truncated according to the size of the symlink, and not the size of the
target file).

open and sftpGet now use sftp_stat, while the remaining methods
(sftpPut, stat, mkdir, rename, symlink) still use sftp_lstat.

M  +4    -2    sftp/kio_sftp.cpp

https://invent.kde.org/network/kio-extras/-/commit/5fd0630699e5d0d150709bf0cd5e935d725137f0
Comment 7 John Kizer 2025-03-28 06:34:08 UTC
*** Bug 501701 has been marked as a duplicate of this bug. ***