Added bound checking to raw disk read for better error messages

This commit is contained in:
Carl Johnsen
2026-02-13 16:42:09 +01:00
parent 79c4cec029
commit cf9eb24254
+9
View File
@@ -159,6 +159,15 @@ namespace Duplicati.Proprietary.DiskImage.Disk
if (m_deviceHandle == null || m_deviceHandle.IsInvalid)
throw new InvalidOperationException("Device handle is invalid.");
if (offset % SectorSize != 0)
throw new InvalidOperationException($"Address {offset:X016} is not a multiple of the sector size {SectorSize}");
if (length % SectorSize != 0)
throw new InvalidOperationException($"The requested length of {length} is not a multiple of sector size {SectorSize}");
if (offset + length > Size)
throw new InvalidOperationException($"The requested read would read beyond disk size: {offset} + {length} > {Size}");
// Move file pointer to the desired offset
var seeked = SetFilePointerEx(m_deviceHandle, offset, out _, SeekOrigin.Begin);
if (!seeked)