Explorar el Código

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...)
Jon Skeet hace 10 años
padre
commit
ca2adbd560
Se han modificado 1 ficheros con 2 adiciones y 2 borrados
  1. 2 2
      csharp/src/ProtocolBuffers/CodedInputStream.cs

+ 2 - 2
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();