From 060e447a7749c981bdc506fe8148e0563279de81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herm=C3=A8s=20B=C3=A9lusca-Ma=C3=AFto?= Date: Sat, 26 Dec 2015 17:08:13 +0000 Subject: [PATCH] [NTVDM]: Cast all the number-of-sectors computations to DWORD/ULONG to prevent potential overflows. Should fix a strange floppy read/write corruption I noticed. svn path=/trunk/; revision=70424 --- reactos/subsystems/mvdm/ntvdm/bios/bios32/dskbios32.c | 4 ++-- reactos/subsystems/mvdm/ntvdm/hardware/disk.c | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/reactos/subsystems/mvdm/ntvdm/bios/bios32/dskbios32.c b/reactos/subsystems/mvdm/ntvdm/bios/bios32/dskbios32.c index 9bc83c08801..a4731787bb4 100644 --- a/reactos/subsystems/mvdm/ntvdm/bios/bios32/dskbios32.c +++ b/reactos/subsystems/mvdm/ntvdm/bios/bios32/dskbios32.c @@ -608,8 +608,8 @@ VOID WINAPI BiosDiskService(LPWORD Stack) setAH(0x03); /* Number of 512-byte sectors in CX:DX */ - NumSectors = DiskImage->DiskInfo.Cylinders * DiskImage->DiskInfo.Heads - * DiskImage->DiskInfo.Sectors; + NumSectors = (ULONG)((ULONG)DiskImage->DiskInfo.Cylinders * DiskImage->DiskInfo.Heads) + * DiskImage->DiskInfo.Sectors; setCX(HIWORD(NumSectors)); setDX(LOWORD(NumSectors)); } diff --git a/reactos/subsystems/mvdm/ntvdm/hardware/disk.c b/reactos/subsystems/mvdm/ntvdm/hardware/disk.c index 4bc4fad11ea..7f448a6f81b 100644 --- a/reactos/subsystems/mvdm/ntvdm/hardware/disk.c +++ b/reactos/subsystems/mvdm/ntvdm/hardware/disk.c @@ -342,7 +342,7 @@ SeekDisk(IN PDISK_IMAGE DiskImage, /* Set position */ // Compute the offset - FilePointer = ((Cylinder * DiskImage->DiskInfo.Heads + Head) + FilePointer = (DWORD)((DWORD)((DWORD)Cylinder * DiskImage->DiskInfo.Heads + Head) * DiskImage->DiskInfo.Sectors + (Sector - 1)) * DiskImage->DiskInfo.SectorSize; FilePointer = SetFilePointer(DiskImage->hDisk, FilePointer, NULL, FILE_BEGIN); @@ -373,7 +373,7 @@ ReadDisk(IN PDISK_IMAGE DiskImage, if (Result != 0x00) return Result; - BytesToRead = NumSectors * DiskImage->DiskInfo.SectorSize; + BytesToRead = (DWORD)NumSectors * DiskImage->DiskInfo.SectorSize; // FIXME: Consider just looping around filling each time the buffer... @@ -434,7 +434,7 @@ WriteDisk(IN PDISK_IMAGE DiskImage, if (Result != 0x00) return Result; - BytesToWrite = NumSectors * DiskImage->DiskInfo.SectorSize; + BytesToWrite = (DWORD)NumSectors * DiskImage->DiskInfo.SectorSize; // FIXME: Consider just looping around filling each time the buffer...