-
Notifications
You must be signed in to change notification settings - Fork 16.1k
Description
What version of protobuf and what language are you using?
Version: master
Language: C#
What operating system (Linux, Windows, ...) and version?
Irrelevant (testing on Windows, but...)
What runtime / compiler are you using (e.g., python version or gcc version)
n/a
What did you do?
The following test fails in the call to ToByteArray():
[Test]
public void TestDefaultValueRoundTrip()
{
var message = new TestAllExtensions();
message.SetExtension(OptionalBoolExtension, false);
Assert.IsFalse(message.GetExtension(OptionalBoolExtension));
Assert.IsTrue(message.HasExtension(OptionalBoolExtension));
var bytes = message.ToByteArray();
var registry = new ExtensionRegistry { OptionalBoolExtension };
var parsed = TestAllExtensions.Parser.WithExtensionRegistry(registry).ParseFrom(bytes);
Assert.IsFalse(parsed.GetExtension(OptionalBoolExtension));
Assert.IsTrue(parsed.HasExtension(OptionalBoolExtension));
}What did you expect to see
A passing test.
What did you see instead?
The test throws during ToByteArray(), because the extension value has a calculated size of 0, due to being the default value. We want to actually write the extension to the output, and we try to... but at that point, not enough space has been allocated.
I have a fix for this, but wanted to file it as an issue first. This is pretty serious in terms of not being able to serialize descriptors that happen to include a default value for an extension - although that's quite rare.