diff options
author | Jon Skeet <jonskeet@google.com> | 2015-08-04 12:38:53 +0100 |
---|---|---|
committer | Jon Skeet <jonskeet@google.com> | 2015-08-05 07:09:43 +0100 |
commit | 15bf55e2251df4ad798a4f88b8514899c26e3dc3 (patch) | |
tree | bc00377662bb39264b003e35c6415856b6bf4caa /csharp/src/Google.Protobuf/CodedInputStream.cs | |
parent | fe355b26ec4646f79b6374a81050a992c9f34565 (diff) | |
download | protobuf-15bf55e2251df4ad798a4f88b8514899c26e3dc3.tar.gz protobuf-15bf55e2251df4ad798a4f88b8514899c26e3dc3.tar.bz2 protobuf-15bf55e2251df4ad798a4f88b8514899c26e3dc3.zip |
Validate that after reading a message, we've consumed as many bytes as we expected to.
We should now have no conformance failures.
Diffstat (limited to 'csharp/src/Google.Protobuf/CodedInputStream.cs')
-rw-r--r-- | csharp/src/Google.Protobuf/CodedInputStream.cs | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/csharp/src/Google.Protobuf/CodedInputStream.cs b/csharp/src/Google.Protobuf/CodedInputStream.cs index fee31e3b..5da03b5c 100644 --- a/csharp/src/Google.Protobuf/CodedInputStream.cs +++ b/csharp/src/Google.Protobuf/CodedInputStream.cs @@ -54,13 +54,37 @@ namespace Google.Protobuf /// </remarks>
public sealed class CodedInputStream
{
+ /// <summary>
+ /// Buffer of data read from the stream or provided at construction time.
+ /// </summary>
private readonly byte[] buffer;
+
+ /// <summary>
+ /// The number of valid bytes in the buffer.
+ /// </summary>
private int bufferSize;
+
private int bufferSizeAfterLimit = 0;
+ /// <summary>
+ /// The position within the current buffer (i.e. the next byte to read)
+ /// </summary>
private int bufferPos = 0;
+
+ /// <summary>
+ /// The stream to read further input from, or null if the byte array buffer was provided
+ /// directly on construction, with no further data available.
+ /// </summary>
private readonly Stream input;
+
+ /// <summary>
+ /// The last tag we read. 0 indicates we've read to the end of the stream
+ /// (or haven't read anything yet).
+ /// </summary>
private uint lastTag = 0;
+ /// <summary>
+ /// The next tag, used to store the value read by PeekTag.
+ /// </summary>
private uint nextTag = 0;
private bool hasNextTag = false;
@@ -456,6 +480,11 @@ namespace Google.Protobuf ++recursionDepth;
builder.MergeFrom(this);
CheckLastTagWas(0);
+ // Check that we've read exactly as much data as expected.
+ if (!ReachedLimit)
+ {
+ throw InvalidProtocolBufferException.TruncatedMessage();
+ }
--recursionDepth;
PopLimit(oldLimit);
}
|