Merge pull request #7531 from RoosterDragon/stream-read-fixes

Fix some broken Stream.Read calls.
This commit is contained in:
Oliver Brakmann
2015-02-23 21:49:49 +01:00
2 changed files with 5 additions and 3 deletions

View File

@@ -315,7 +315,7 @@ namespace OpenRA.FileFormats
// Full frame-modifier
case "CBFZ":
var decodeMode = s.Peek() == 0;
s.Read(fileBuffer, 0, subchunkLength);
s.ReadBytes(fileBuffer, 0, subchunkLength);
Array.Clear(cbf, 0, cbf.Length);
Array.Clear(cbfBuffer, 0, cbfBuffer.Length);
var decodeCount = 0;
@@ -386,7 +386,7 @@ namespace OpenRA.FileFormats
return;
case "VPRZ":
Array.Clear(origData, 0, origData.Length);
s.Read(fileBuffer, 0, subchunkLength);
s.ReadBytes(fileBuffer, 0, subchunkLength);
if (fileBuffer[0] != 0)
vtprSize = Format80.DecodeInto(fileBuffer, origData);
else
@@ -394,7 +394,7 @@ namespace OpenRA.FileFormats
return;
case "VPTR":
Array.Clear(origData, 0, origData.Length);
s.Read(origData, 0, subchunkLength);
s.ReadBytes(origData, 0, subchunkLength);
vtprSize = subchunkLength;
return;
default:

View File

@@ -28,6 +28,8 @@ namespace OpenRA
public static void ReadBytes(this Stream s, byte[] buffer, int offset, int count)
{
if (count < 0)
throw new ArgumentOutOfRangeException("count", "Non-negative number required.");
while (count > 0)
{
int bytesRead;