[Parted-maintainers] _primary_constraint(): start_geom is uninitialized if min_geom==0 && cylinder_size < dev->length. Debian bug #602568

Jean-Christian de Rivaz jc at eclis.ch
Mon Nov 8 14:03:23 UTC 2010


Hello,

I try to fix a bug I have found with parted-2.3 while using a special 
USB key (Model: disk2go PURE II) that expose two storage devices: a 
small 5MB device and a regular 2GB device. Here are the 5MB one viewed 
by using fdisk:

fdisk -l /dev/sdb

Disk /dev/sdb: 5 MB, 5242880 bytes
256 heads, 32 sectors/track, 1 cylinders
Units = cylinders of 8192 * 512 = 4194304 bytes
Disk identifier: 0x00000000

    Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1           1        4080    6  FAT16

The first 5MB device have, acoording to parted-2.3, a cylinder size 
(16065) not smaller than the device length (10240), causing the 
PedGeometry start_geom of the function _primary_constraint() (file 
libparted/labels/dos.c) to stay uninitialized. I suspect that the 
condition "cylinder_size < dev->length" have bee introduced for the 
memory-mapped test as explained into the comment above the condition. 
Unfortunately, it seem that the true real world contain at least a type 
of USB key sold with a storage device that go wrong with this condition.

I don't know the parted code enough to propose better patch than the 
attached one that remove the condition. Obviously it will cause the 
memory-mapped test to fail. With the proposed patch, parted-2.3 work as 
expected when compiled without optimization:

jcdr at point:~/parted-testing/build-O0$ parted/parted /dev/sdb print
WARNING: You are not superuser.  Watch out for permissions.
Error: Can't have the end before the start! (start sector=16065 
length=-5825)
Model: disk2go PURE II (scsi)
Disk /dev/sdb: 5243kB
Sector size (logical/physical): 512B/512B
Partition Table: msdos

Number  Start  End     Size    Type     File system  Flags
  1      5120B  5243kB  5238kB  primary


The bug was first reported to Debian: 
http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=602568 but this is 
reproductible without any Debian patch.

Warning: as this debug screen capture show, this bug occur only if 
parted is compiled without any optimization: 
http://bugs.debian.org/cgi-bin/bugreport.cgi?msg=71;filename=Capture-parted-2.3.png;att=1;bug=602568

Regards,

Jean-Christian de Rivaz
-------------- next part --------------
A non-text attachment was scrubbed...
Name: parted-2.3-fix-uninitialized-start_geom.patch
Type: text/x-patch
Size: 885 bytes
Desc: not available
URL: <http://lists.alioth.debian.org/pipermail/parted-maintainers/attachments/20101108/fab98553/attachment.bin>


More information about the Parted-maintainers mailing list