mirror of
https://github.com/pbatard/rufus.git
synced 2025-05-27 13:14:26 -04:00
[misc] fix division by zero if the sector size is misreported
* It looks like some disks may report a sector size of zero * Hopefully, this will address #352 (but some report about the detected sector size from people observing the crash would be nice)
This commit is contained in:
parent
270ad743ab
commit
60c66ef813
3 changed files with 14 additions and 7 deletions
|
@ -602,7 +602,7 @@ int GetDrivePartitionData(DWORD DriveIndex, char* FileSystemName, DWORD FileSyst
|
|||
FileSystemName[0] = 0;
|
||||
volume_name = GetLogicalName(DriveIndex, TRUE, FALSE);
|
||||
if ((volume_name == NULL) || (!GetVolumeInformationA(volume_name, NULL, 0, NULL, NULL, NULL, FileSystemName, FileSystemNameSize))) {
|
||||
uprintf("No volume information for disk 0x%02x\n", DriveIndex);
|
||||
uprintf("No volume information for drive 0x%02x\n", DriveIndex);
|
||||
}
|
||||
safe_free(volume_name);
|
||||
|
||||
|
@ -617,6 +617,11 @@ int GetDrivePartitionData(DWORD DriveIndex, char* FileSystemName, DWORD FileSyst
|
|||
safe_closehandle(hPhysical);
|
||||
return 0;
|
||||
}
|
||||
if (DiskGeometry->Geometry.BytesPerSector < 512) {
|
||||
uprintf("WARNING: Drive 0x%02x reports a sector size of %d - Correcting to 512 bytes.\n",
|
||||
DriveIndex, DiskGeometry->Geometry.BytesPerSector);
|
||||
DiskGeometry->Geometry.BytesPerSector = 512;
|
||||
}
|
||||
SelectedDrive.DiskSize = DiskGeometry->DiskSize.QuadPart;
|
||||
memcpy(&SelectedDrive.Geometry, &DiskGeometry->Geometry, sizeof(DISK_GEOMETRY));
|
||||
uprintf("Disk type: %s, Sector Size: %d bytes\n", (DiskGeometry->Geometry.MediaType == FixedMedia)?"Fixed":"Removable",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue