diff options
author | Jon Skeet <skeet@pobox.com> | 2015-06-12 09:57:04 +0100 |
---|---|---|
committer | Jon Skeet <skeet@pobox.com> | 2015-06-12 09:57:04 +0100 |
commit | ca2adbd560baa504dd721fb68e81d911392b981d (patch) | |
tree | d10f7e25e17909cefa41a86b5f881fc61f0be9a4 | |
parent | eb70bd0b6019dc957eb36e9cefb1c1e9e5a5a890 (diff) | |
download | protobuf-ca2adbd560baa504dd721fb68e81d911392b981d.tar.gz protobuf-ca2adbd560baa504dd721fb68e81d911392b981d.tar.bz2 protobuf-ca2adbd560baa504dd721fb68e81d911392b981d.zip |
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...)
-rw-r--r-- | csharp/src/ProtocolBuffers/CodedInputStream.cs | 4 |
1 files 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();
|