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;
public sealed partial class CopyQm
{
@@ -48,7 +49,7 @@ public sealed partial class CopyQm
return false;
var hdr = new byte[133];
stream.Read(hdr, 0, 133);
stream.EnsureRead(hdr, 0, 133);
var magic = BitConverter.ToUInt16(hdr, 0);

View File

@@ -50,7 +50,7 @@ public sealed partial class CopyQm
var hdr = new byte[133];
stream.Read(hdr, 0, 133);
stream.EnsureRead(hdr, 0, 133);
_header = Marshal.ByteArrayToStructureLittleEndian<Header>(hdr);
AaruConsole.DebugWriteLine("CopyQM plugin", "header.magic = 0x{0:X4}", _header.magic);
@@ -84,7 +84,7 @@ public sealed partial class CopyQm
AaruConsole.DebugWriteLine("CopyQM plugin", "header.drive = {0}", _header.drive);
var cmt = new byte[_header.commentLength];
stream.Read(cmt, 0, _header.commentLength);
stream.EnsureRead(cmt, 0, _header.commentLength);
_imageInfo.Comments = StringHandlers.CToString(cmt);
_decodedImage = new MemoryStream();
@@ -94,7 +94,7 @@ public sealed partial class CopyQm
{
var runLengthBytes = new byte[2];
if(stream.Read(runLengthBytes, 0, 2) != 2)
if(stream.EnsureRead(runLengthBytes, 0, 2) != 2)
break;
var runLength = BitConverter.ToInt16(runLengthBytes, 0);
@@ -120,7 +120,7 @@ public sealed partial class CopyQm
case > 0:
{
var nonRepeated = new byte[runLength];
stream.Read(nonRepeated, 0, runLength);
stream.EnsureRead(nonRepeated, 0, runLength);
_decodedImage.Write(nonRepeated, 0, runLength);
foreach(byte c in nonRepeated)