diff --git a/sources/OpenMcdf.Extensions/StreamDecorator.cs b/sources/OpenMcdf.Extensions/StreamDecorator.cs index ee3b04a1..b79202b8 100644 --- a/sources/OpenMcdf.Extensions/StreamDecorator.cs +++ b/sources/OpenMcdf.Extensions/StreamDecorator.cs @@ -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;