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

@@ -49,7 +49,7 @@ public sealed partial class PartClone
return false;
var pHdrB = new byte[Marshal.SizeOf<Header>()];
stream.Read(pHdrB, 0, Marshal.SizeOf<Header>());
stream.EnsureRead(pHdrB, 0, Marshal.SizeOf<Header>());
_pHdr = Marshal.ByteArrayToStructureLittleEndian<Header>(pHdrB);
if(stream.Position + (long)_pHdr.totalBlocks > stream.Length)
@@ -58,7 +58,7 @@ public sealed partial class PartClone
stream.Seek((long)_pHdr.totalBlocks, SeekOrigin.Current);
var bitmagic = new byte[8];
stream.Read(bitmagic, 0, 8);
stream.EnsureRead(bitmagic, 0, 8);
return _partCloneMagic.SequenceEqual(_pHdr.magic) && _biTmAgIc.SequenceEqual(bitmagic);
}