Skip to content

Commit

Permalink
Truncate StreamDecorator reads
Browse files Browse the repository at this point in the history
Fixes: #184
  • Loading branch information
jeremy-visionaid committed Oct 10, 2024
1 parent ceb409e commit b761843
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 b761843

Please sign in to comment.