Skip to content

Commit

Permalink
Truncate StreamDecorator reads
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremy-visionaid committed Oct 9, 2024
1 parent 578d5a6 commit 321a8f4
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions sources/OpenMcdf.Extensions/StreamDecorator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ public override int Read(byte[] buffer, int offset, int count)
if (position >= cfStream.Size)
return 0;

int maxReadableLength = (int)Math.Min(int.MaxValue, Length - Position);
count = Math.Max(0, Math.Min(maxReadableLength, count));
if (count == 0)
return 0;

count = cfStream.Read(buffer, position, offset, count);
position += count;
return count;
Expand Down

0 comments on commit 321a8f4

Please sign in to comment.