After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 764658 - GParted crashes when reading NTFS usage when there is no /dev/PTN entry
GParted crashes when reading NTFS usage when there is no /dev/PTN entry
Status: RESOLVED FIXED
Product: gparted
Classification: Other
Component: application
GIT HEAD
Other Linux
: Normal normal
: ---
Assigned To: Mike Fleetwood
gparted maintainers alias
Depends on:
Blocks:
 
 
Reported: 2016-04-05 19:11 UTC by Mike Fleetwood
Modified: 2016-04-26 15:57 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Fix crash reading NTFS usage when there is no /dev/PTN entry (v1) (8.38 KB, patch)
2016-04-06 18:02 UTC, Mike Fleetwood
none Details | Review

Description Mike Fleetwood 2016-04-05 19:11:00 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.
Comment 1 Mike Fleetwood 2016-04-06 18:02:50 UTC
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
Comment 2 Curtis Gedak 2016-04-06 19:41:11 UTC
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
Comment 3 Curtis Gedak 2016-04-06 19:48:53 UTC
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
Comment 4 Mike Fleetwood 2016-04-07 14:06:05 UTC
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
Comment 5 Curtis Gedak 2016-04-07 16:01:21 UTC
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
Comment 6 Curtis Gedak 2016-04-26 15:57:06 UTC
This enhancement was included in the GParted 0.26.0 release on April 26, 2016.