diff --git a/csharp/src/ProtocolBuffers/CodedInputStream.cs b/csharp/src/ProtocolBuffers/CodedInputStream.cs index 37774d017735..033132c186ce 100644 --- a/csharp/src/ProtocolBuffers/CodedInputStream.cs +++ b/csharp/src/ProtocolBuffers/CodedInputStream.cs @@ -1813,7 +1813,8 @@ private void SkipImpl(int amountToSkip) byte[] skipBuffer = new byte[1024]; while (amountToSkip > 0) { - int bytesRead = input.Read(skipBuffer, 0, skipBuffer.Length); + int bytesRead = input.Read( + skipBuffer, 0, Math.Min(skipBuffer.Length, amountToSkip)); if (bytesRead <= 0) { throw InvalidProtocolBufferException.TruncatedMessage();