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

@@ -35,6 +35,7 @@ namespace Aaru.DiscImages;
using System;
using System.IO;
using Aaru.CommonTypes.Interfaces;
using Aaru.Helpers;
using Claunia.RsrcFork;
public sealed partial class Ndif
@@ -57,7 +58,7 @@ public sealed partial class Ndif
Stream dataFork = imageFilter.GetDataForkStream();
var udifMagic = new byte[4];
dataFork.Read(udifMagic, 0, 4);
dataFork.EnsureRead(udifMagic, 0, 4);
if(BitConverter.ToUInt32(udifMagic, 0) == 0x796C6F6B)
return false;

View File

@@ -339,7 +339,7 @@ public sealed partial class Ndif
{
var cmpBuffer = new byte[currentChunk.length];
_imageStream.Seek(currentChunk.offset, SeekOrigin.Begin);
_imageStream.Read(cmpBuffer, 0, cmpBuffer.Length);
_imageStream.EnsureRead(cmpBuffer, 0, cmpBuffer.Length);
int realSize;
switch(currentChunk.type)
@@ -402,7 +402,7 @@ public sealed partial class Ndif
case CHUNK_TYPE_COPY:
_imageStream.Seek(currentChunk.offset + relOff, SeekOrigin.Begin);
buffer = new byte[SECTOR_SIZE];
_imageStream.Read(buffer, 0, buffer.Length);
_imageStream.EnsureRead(buffer, 0, buffer.Length);
if(_sectorCache.Count >= MAX_CACHED_SECTORS)
_sectorCache.Clear();