GNOME Bugzilla – Bug 764658
GParted crashes when reading NTFS usage when there is no /dev/PTN entry
Last modified: 2016-04-26 15:57:06 UTC
The investigation into this bug was carried out in bug 764369 comment 2 onwards. The bug has not been included in any release because it was introduced in this commit after the latest 0.25.0 was released. Record file system block size where known (#760709) https://git.gnome.org/browse/gparted/commit/?id=324d99a172848e4ff3fb7eb189f490bb4e6c53e5 Quoting the preliminary commit message for more details ... --8<-- Fix crash reading NTFS usage when there is no /dev/PTN entry (#XXXXXX) On a 64-bit distribution, with an NTFS file system in a partition without a /dev entry then GParted will crash when attempting to read the file system usage. Not having a /dev entry for the partition is rare and only known to occur for the disk devices used within Fake RAID (dmraid) arrays, and then only on Ubuntu 12.04 LTS. Other/newer distributions do create /dev entries for partitions found on disk devices within Fake RAID arrays. Create mirror Fake RAID array: # dmraid -f isw -C MyArray --type 1 --disk /dev/sdc,/dev/sdd # dmraid -ay Create NTFS partition on the Fake RAID array. On refresh GParted crashes: # ./gpartedbin (gpartedbin:590): glibmm-ERROR **: unhandled exception (type std::exception) in signal handler: what: basic_string::assign Without a /dev/sdc1 device entry the ntfsresize command reports this: # ntfsresize --info --force --no-progress-bar /dev/sdc1 ntfsresize v2015.3.14 (libntfs-3g) ERROR(2): Failed to check '/dev/sdc1' mount state: No such file or directory Probably /etc/mtab is missing. It's too risky to continue. You might try an another Linux distro. The problem code in ntfs::set_used_sectors(): 145 index = output.find( "Cluster size" ); 146 if ( index == output.npos || 147 sscanf( output.substr( index ).c_str(), "Cluster size : %Ld", &S ) != 1 ) As "Cluster size" did not exist in the output find() returned the not found token of string::npos, which in a 64-bit environment is represented by 2^64-1. However it was saved in the variable index of type unsigned integer, which is only a 32-bit integer, thus truncating it to 2^32-1. Therefore the comparison failed and sscanf() tried to parse the output starting at offset 2^32-1 which resulted in the crash. Introduced by commit: 324d99a172848e4ff3fb7eb189f490bb4e6c53e5 Record file system block size where known (#760709) Fix by following the same pattern of the other comparisons in ntfs::set_used_sectors() which checks if index is less than the output length.
Created attachment 325504 [details] [review] Fix crash reading NTFS usage when there is no /dev/PTN entry (v1) Hi Curtis, Here is the fix for this. I was able to re-produce this on any 64-bit OS by simply removing the /dev/PTN entry by adding this hack into ntfs::set_used_sectors(): if ( path == "/dev/sdc1" ) unlink( path.c_str() ); Thanks, Mike
Thank you Mike for developing a patch set to address these issues. I have just begun testing. One small change I have made is to remove the following two lines from the end of the first commit message: Conflicts: src/ntfs.cc I'm guessing that you did not intend to append these lines in the commit message. Curtis
Hi Mike, This patch set looks good to me and does not crash on my development computer. I plan to commit patch set v1 from comment #1 with the adjustment from comment #2 to the master branch tomorrow. Curtis
Hi Curtis, Woops. Yes, I should remove "Conflicts: src/ntfs.cc". Happens because I copied patches between branches (with and without debugging code) so the underlying code to which the patch is applied is different so Git isn't able to automatically apply it and gets the user to fix it up. Git adds the conflicts lines to the commit message and I forgot to remove. Thanks, Mike
The patch set in comment #1 has been committed to the git repository. The relevant commits can be viewed at the following links: Fix crash reading NTFS usage when there is no /dev/PTN entry (#764658) https://git.gnome.org/browse/gparted/commit/?id=366152e4499fce4560e9889489fca8b42c5f67d0 Replace 32-bit member variable "index" with wider local variables (#764658) https://git.gnome.org/browse/gparted/commit/?id=a681f9f63733d9834179a02ce65438c5b6cb4b96
This enhancement was included in the GParted 0.26.0 release on April 26, 2016.