Use Stream extension to ensure read operations return the requested number of bytes (unless EOF arrives first).

This commit is contained in:
2022-11-14 09:43:16 +00:00
parent f90cc6593f
commit 0eb589d785
178 changed files with 862 additions and 780 deletions

View File

@@ -93,18 +93,18 @@ public sealed partial class Imd
if((head & 1) == 1)
_imageInfo.Heads = 2;
stream.Read(idmap, 0, idmap.Length);
stream.EnsureRead(idmap, 0, idmap.Length);
if((head & SECTOR_CYLINDER_MAP_MASK) == SECTOR_CYLINDER_MAP_MASK)
stream.Read(cylmap, 0, cylmap.Length);
stream.EnsureRead(cylmap, 0, cylmap.Length);
if((head & SECTOR_HEAD_MAP_MASK) == SECTOR_HEAD_MAP_MASK)
stream.Read(headmap, 0, headmap.Length);
stream.EnsureRead(headmap, 0, headmap.Length);
if(n == 0xFF)
{
var bpsbytes = new byte[spt * 2];
stream.Read(bpsbytes, 0, bpsbytes.Length);
stream.EnsureRead(bpsbytes, 0, bpsbytes.Length);
for(var i = 0; i < spt; i++)
bps[i] = BitConverter.ToUInt16(bpsbytes, i * 2);
@@ -138,7 +138,7 @@ public sealed partial class Imd
case SectorType.Deleted:
case SectorType.Error:
case SectorType.DeletedError:
stream.Read(data, 0, data.Length);
stream.EnsureRead(data, 0, data.Length);
if(!track.ContainsKey(idmap[i]))
track.Add(idmap[i], data);