From ca2adbd560baa504dd721fb68e81d911392b981d Mon Sep 17 00:00:00 2001 From: Jon Skeet Date: Fri, 12 Jun 2015 09:57:04 +0100 Subject: Fix incorrect handling of non-seekable streams. This mirrors commit 7c86bbbc7a3365c034d82173b38ec4427b98b3b2 in the pull request to the main protobuf project, but also reduces the size of the buffer created. (There's no point in creating a 1024-byte buffer if we're only skipping 5 bytes...) --- csharp/src/ProtocolBuffers/CodedInputStream.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/csharp/src/ProtocolBuffers/CodedInputStream.cs b/csharp/src/ProtocolBuffers/CodedInputStream.cs index cb47f1c2..17fcc64b 100644 --- a/csharp/src/ProtocolBuffers/CodedInputStream.cs +++ b/csharp/src/ProtocolBuffers/CodedInputStream.cs @@ -1429,10 +1429,10 @@ namespace Google.Protobuf } else { - byte[] skipBuffer = new byte[1024]; + byte[] skipBuffer = new byte[Math.Min(1024, amountToSkip)]; 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(); -- cgit v1.2.3