Bug 502141

Summary: App crashes in SfdiskBackend::readSectorsUsed() while refreshing if USB flash drive needing repairs is plugged in
Product: [Applications] partitionmanager Reporter: Nate Graham <nate>
Component: generalAssignee: Andrius Štikonas <andrius>
Status: RESOLVED FIXED    
Severity: crash CC: christoph, corroding.worsening266, farchord, kde, kdebugs, Keelung.Yang, planetory, thomas.bettler
Priority: HI    
Version First Reported In: Git   
Target Milestone: ---   
Platform: Other   
OS: Linux   
Latest Commit: Version Fixed In:
Sentry Crash Report:
Attachments: Stuck here now with that patch applied
Output of those commands
Debug output

Description Nate Graham 2025-03-28 21:13:35 UTC
SUMMARY
I have a USB flash drive that evidently needs repairs (as detected by Plasma's Disks & Devices popup). When I launch Partition Manager or refresh it while the drive is plugged in, the app crashes.

STEPS TO REPRODUCE
1. Plug in a USB flash drive in need of repair
2. Launch Partition Manager and authenticate

OBSERVED RESULT
The app crashes 100% of the time:

#0  __pthread_kill_implementation
    (threadid=<optimized out>, signo=signo@entry=11, no_tid=no_tid@entry=0) at pthread_kill.c:44
#1  0x00007faf7f07fbc3 in __pthread_kill_internal (threadid=<optimized out>, signo=11)
    at pthread_kill.c:78
#2  0x00007faf7f026f9e in __GI_raise (sig=11) at ../sysdeps/posix/raise.c:26
#3  0x00007faf81c3554b in KCrash::defaultCrashHandler (sig=11)
    at /home/nate/kde/src/kcrash/src/kcrash.cpp:605
#4  0x00007faf7f027050 in <signal handler called> () at /lib64/libc.so.6
#5  0x00007faf680ce9b4 in SfdiskBackend::readSectorsUsed (d=..., p=..., mountPoint=...)
    at /home/nate/kde/src/kpmcore/src/plugins/sfdisk/sfdiskbackend.cpp:523
#6  0x00007faf680d02f5 in SfdiskBackend::scanWholeDevicePartition
    (this=this@entry=0x7faf64009600, d=...)
    at /home/nate/kde/src/kpmcore/src/plugins/sfdisk/sfdiskbackend.cpp:345
#7  0x00007faf680d45d9 in SfdiskBackend::scanDevice
    (this=0x7faf64009600, deviceNode=<optimized out>)
    at /home/nate/kde/src/kpmcore/src/plugins/sfdisk/sfdiskbackend.cpp:297
#8  0x00007faf680d104b in SfdiskBackend::scanDevices (this=0x7faf64009600, scanFlags=...)
    at /home/nate/kde/src/kpmcore/src/plugins/sfdisk/sfdiskbackend.cpp:106
#9  0x00007faf8233a842 in DeviceScanner::scan (this=0x398d2720)
    at /home/nate/kde/src/kpmcore/src/core/devicescanner.cpp:56
#10 0x00007faf7f8b67e9 in operator() (__closure=<optimized out>)
    at /usr/src/debug/qt6-qtbase-6.8.2-3.fc41.x86_64/src/corelib/thread/qthread_unix.cpp:375
#11 (anonymous namespace)::terminate_on_exception<QThreadPrivate::start(void*)::<lambda()> >
    (t=<optimized out>)
    at /usr/src/debug/qt6-qtbase-6.8.2-3.fc41.x86_64/src/corelib/thread/qthread_unix.cpp:311
#12 QThreadPrivate::start (arg=0x398d2720)
    at /usr/src/debug/qt6-qtbase-6.8.2-3.fc41.x86_64/src/corelib/thread/qthread_unix.cpp:339
#13 0x00007faf7f07dba8 in start_thread (arg=<optimized out>) at pthread_create.c:448
#14 0x00007faf7f101b8c in __GI___clone3 () at ../sysdeps/unix/sysv/linux/x86_64/clone3.S:78


EXPECTED RESULT
No crash.


SOFTWARE/OS VERSIONS
Operating System: Fedora Linux 41
KDE Plasma Version: 6.3.80
KDE Frameworks Version: 6.13.0
Qt Version: 6.8.2
Kernel Version: 6.13.8-200.fc41.x86_64 (64-bit)
Graphics Platform: Wayland
Processors: 16 × AMD Ryzen 7 7840U w/ Radeon™ 780M Graphics
Memory: 16 GB of RAM (14.9 GB usable)
Graphics Processor: AMD Radeon 780M
Comment 1 Andrius Štikonas 2025-03-28 22:42:08 UTC
Could you see if the following patch helps?


diff --git a/src/plugins/sfdisk/sfdiskbackend.cpp b/src/plugins/sfdisk/sfdiskbackend.cpp
index e47c4e5..2fe99dd 100644
--- a/src/plugins/sfdisk/sfdiskbackend.cpp
+++ b/src/plugins/sfdisk/sfdiskbackend.cpp
@@ -515,6 +515,8 @@ bool SfdiskBackend::updateDevicePartitionTable(Device &d, const QJsonObject &jso
 */
 void SfdiskBackend::readSectorsUsed(const Device& d, Partition& p, const QString& mountPoint)
 {
+    if (p.isFileSystemNullptr())
+        return;
     if (!mountPoint.isEmpty() && p.fileSystem().type() != FileSystem::Type::LinuxSwap && p.fileSystem().type() != FileSystem::Type::Lvm2_PV) {
         const QStorageInfo storage = QStorageInfo(mountPoint);
         if (p.isMounted() && storage.isValid())
Comment 2 Nate Graham 2025-03-28 22:45:08 UTC
Thank you! That does fix the crash, but then it gets stuck at "Scanning device: '/dev/sdb/' ".
Comment 3 Nate Graham 2025-03-28 22:45:26 UTC
Created attachment 179830 [details]
Stuck here now with that patch applied
Comment 4 Nate Graham 2025-03-28 22:45:55 UTC
If it's related, I see this in the log output:

unknown file system type  "dos"  on  "/dev/sdb"
Comment 5 Nate Graham 2025-03-28 22:46:13 UTC
(and yes, it is ostensibly FAT32-formatted)
Comment 6 Andrius Štikonas 2025-03-28 22:58:41 UTC
(In reply to Nate Graham from comment #4)
> If it's related, I see this in the log output:
> 
> unknown file system type  "dos"  on  "/dev/sdb"

That might be just checking whether it is full disk FAT partition... MBR has somewhat similar signature.
Do you know if that USB has partition table or is it full disk filesystem?

I guess the following info could be useful
lsblk /dev/sdb
udevadm info --query=property /dev/sdb
udevadm info --query=property /dev/sdb1 (if it has partition table)
Comment 7 Andrius Štikonas 2025-03-28 22:59:39 UTC
Perhaps you could also obtain backtrace from the stuck instance? Right now I have no idea where it is stuck.
Comment 8 Nate Graham 2025-03-28 23:06:17 UTC
Created attachment 179831 [details]
Output of those commands
Comment 9 Nate Graham 2025-03-28 23:09:50 UTC
I do notice that what's stuck is a spawned /usr/libexec/kpmcore_externalcommand process. If I quit the app, that keeps going. I'll try to get backtraces of both.
Comment 10 Nate Graham 2025-03-28 23:12:04 UTC
App is stuck here:

#0  0x00007ffff4cf4370 in __GI_ppoll
    (fds=fds@entry=0xc62a60, nfds=nfds@entry=1, timeout=<optimized out>, 
    timeout@entry=0x7fffffffcd00, sigmask=sigmask@entry=0x0)
    at ../sysdeps/unix/sysv/linux/ppoll.c:42
#1  0x00007ffff498e8a3 in ppoll (__fds=0xc62a60, __nfds=1, __timeout=0x7fffffffcd00, __ss=0x0)
    at /usr/include/bits/poll2.h:101
#2  g_main_context_poll_unlocked
    (priority=<optimized out>, context=0x7fffdc000f00, timeout_usec=<optimized out>, fds=0xc62a60, n_fds=1) at ../glib/gmain.c:4591
#3  g_main_context_iterate_unlocked.isra.0
    (context=context@entry=0x7fffdc000f00, block=block@entry=1, dispatch=dispatch@entry=1, self=<optimized out>) at ../glib/gmain.c:4268
#4  0x00007ffff492f783 in g_main_context_iteration (context=0x7fffdc000f00, may_block=1)
    at ../glib/gmain.c:4338
#5  0x00007ffff55ef2b3 in QEventDispatcherGlib::processEvents (this=0x4d07a0, flags=...)
    at /usr/src/debug/qt6-qtbase-6.8.2-3.fc41.x86_64/src/corelib/kernel/qeventdispatcher_glib.cpp:399
#6  0x00007ffff5300993 in QEventLoop::exec (this=this@entry=0x7fffffffce70, flags=..., 
    flags@entry=...)
    at /usr/src/debug/qt6-qtbase-6.8.2-3.fc41.x86_64/src/corelib/global/qflags.h:34
#7  0x00007ffff52fbf6e in QCoreApplication::exec ()
    at /usr/src/debug/qt6-qtbase-6.8.2-3.fc41.x86_64/src/corelib/global/qflags.h:74
#8  0x00007ffff5ad7d3d in QGuiApplication::exec ()
    at /usr/src/debug/qt6-qtbase-6.8.2-3.fc41.x86_64/src/gui/kernel/qguiapplication.cpp:1975
#9  0x00007ffff643d929 in QApplication::exec ()
    at /usr/src/debug/qt6-qtbase-6.8.2-3.fc41.x86_64/src/widgets/kernel/qapplication.cpp:2564
#10 0x0000000000406b2c in main (argc=<optimized out>, argv=<optimized out>)
    at /home/nate/kde/src/partitionmanager/src/main.cpp:143





externalcommand process is stuck here:

#0  0x00007fcd674f4370 in ppoll () at /lib64/libc.so.6
#1  0x00007fcd679518a3 in g_main_context_iterate_unlocked.isra () at /lib64/libglib-2.0.so.0
#2  0x00007fcd678f2783 in g_main_context_iteration () at /lib64/libglib-2.0.so.0
#3  0x00007fcd67def2b3 in QEventDispatcherGlib::processEvents(QFlags<QEventLoop::ProcessEventsFlag>) () at /lib64/libQt6Core.so.6
#4  0x00007fcd67b00993 in QEventLoop::exec(QFlags<QEventLoop::ProcessEventsFlag>) ()
    at /lib64/libQt6Core.so.6
#5  0x00007fcd67afbf6e in QCoreApplication::exec() () at /lib64/libQt6Core.so.6
#6  0x000055939ab83a4a in main ()
Comment 11 Andrius Štikonas 2025-03-28 23:36:40 UTC
(In reply to Nate Graham from comment #9)
> I do notice that what's stuck is a spawned
> /usr/libexec/kpmcore_externalcommand process. If I quit the app, that keeps
> going. I'll try to get backtraces of both.

That's kind of intentional, it tries to finish current task rather than killing it to reduce chance of data loss.

Hmm, I can't tell much from these two backtraces, looks like it's just in the even loop. Perhaps running it with KPMCORE_DEBUG=y ./partitionmanager would print which command it's attempting to run?
Comment 12 Nate Graham 2025-03-28 23:48:00 UTC
Created attachment 179834 [details]
Debug output

It appears to be running `fsck.fat -n -v /dev/sdc1`. I'm attaching the full debug output.
Comment 13 Andrius Štikonas 2025-03-29 01:19:47 UTC
(In reply to Nate Graham from comment #12)
> Created attachment 179834 [details]
> Debug output
> 
> It appears to be running `fsck.fat -n -v /dev/sdc1`. I'm attaching the full
> debug output.

Hmm, does that also get stuck when running manually? Not sure how we can detect this automatically.

Anyway, I think the crash fixed can be pushed.
Comment 14 Andrius Štikonas 2025-03-29 01:21:39 UTC
Crash fixed pushed to https://invent.kde.org/system/kpmcore/-/commit/458ef81f2e424f13cdea44d2d89b8260b463e34e
Comment 15 Nate Graham 2025-03-29 02:16:08 UTC
If I run the command by hand, it appears to find approximately ten trillion issues inside /.Spotlight-V100/Store-V2/C64039E9-5043-4001-B62F-51236F7144F9/journals.live_priority/FSCK0000.000, like this:

/.Spotlight-V100/Store-V2/C64039E9-5043-4001-B62F-51236F7144F9/journals.live_priority/FSCK0000.000/0áw0
  Bad short file name (0áw0).
  Auto-renaming it.
  Renamed to FSCK0002.427
/.Spotlight-V100/Store-V2/C64039E9-5043-4001-B62F-51236F7144F9/journals.live_priority/FSCK0000.000/╩3░Ö0┬!.:Ö
  Bad short file name (╩3░Ö0┬!.:Ö).
  Auto-renaming it.
  Renamed to FSCK0002.428
/.Spotlight-V100/Store-V2/C64039E9-5043-4001-B62F-51236F7144F9/journals.live_priority/FSCK0000.000/O@ÉÖüÆa.
  Bad short file name (O@ÉÖüÆa.).
  Auto-renaming it.
  Renamed to FSCK0002.429
/.Spotlight-V100/Store-V2/C64039E9-5043-4001-B62F-51236F7144F9/journals.live_priority/FSCK0000.000/K@0¾üÜ .ó!
  Bad short file name (K@0¾üÜ .ó!).
  Auto-renaming it.
  Renamed to FSCK0002.430


Endless amount of this. It's very strange because that's something that would be created by a MacOS machine, and to my knowledge this disk has never touched a Mac. It's the external storage disk on my 3D printer.

So I guess the command is doing what it should, though it's... just never finishing. Maybe eventually if I let it run for hours or something, it might finish!
Comment 16 Nate Graham 2025-03-29 02:22:35 UTC
It appears to be super duper corrupted. It won't mount read/write, only RO. My intention was to use Partition Manager to erase it, but I can't since it runs this never-ending fsck on launch.
Comment 17 Andrius Štikonas 2025-03-29 10:16:44 UTC
(In reply to Nate Graham from comment #16)
> It appears to be super duper corrupted. It won't mount read/write, only RO.
> My intention was to use Partition Manager to erase it, but I can't since it
> runs this never-ending fsck on launch.

Hmm, I didn't expect fsck on boot but it looks like specifically for FAT fsck.vfat -n -v is used to read Used Space:
https://invent.kde.org/system/kpmcore/-/blob/master/src/fs/fat12.cpp?ref_type=heads#L113

I guess the proper fix would be to add timeout option to this command.

As a quick hack return -1; at the beginning of that function should unblock you.
Comment 18 Nate Graham 2025-03-29 21:32:37 UTC
Or maybe just a cancel button in case a process hangs.

The crash is fixed; closing as resolved now. :) I'll let you ponder over if and how to address the other issues brought up here. Thanks a lot for the rapid response!
Comment 19 Andrius Štikonas 2025-04-24 11:42:01 UTC
*** Bug 503148 has been marked as a duplicate of this bug. ***
Comment 20 Andrius Štikonas 2025-04-24 11:42:05 UTC
*** Bug 503280 has been marked as a duplicate of this bug. ***
Comment 21 Antonio Rojas 2025-04-26 21:20:15 UTC
*** Bug 503399 has been marked as a duplicate of this bug. ***
Comment 22 Antonio Rojas 2025-04-26 21:20:37 UTC
*** Bug 503400 has been marked as a duplicate of this bug. ***
Comment 23 Antonio Rojas 2025-04-28 05:40:02 UTC
*** Bug 503452 has been marked as a duplicate of this bug. ***
Comment 24 Antonio Rojas 2025-04-30 22:43:41 UTC
*** Bug 503595 has been marked as a duplicate of this bug. ***
Comment 25 Andrius Štikonas 2025-05-06 15:56:20 UTC
*** Bug 503842 has been marked as a duplicate of this bug. ***
Comment 26 Keelung 2025-05-17 13:32:00 UTC
*** Bug 503842 has been marked as a duplicate of this bug. ***
Comment 27 Andrius Štikonas 2025-06-22 19:15:23 UTC
*** Bug 505990 has been marked as a duplicate of this bug. ***