commit | 9da84aef9d8126ac3da665f3c163e3cb4af31b6d | [log] [tgz] |
---|---|---|
author | Ömer Sinan Ağacan <[email protected]> | Tue Mar 29 14:16:43 2022 +0200 |
committer | GitHub <[email protected]> | Tue Mar 29 14:16:43 2022 +0200 |
tree | 1acbec915712f42580542e0d76d9035867689c44 | |
parent | 6be405f9699bbebc502f199af1427d695b7546b2 [diff] |
Fix a potential issue in CodedBufferWriter (#594) Currently `CodedBufferWriter`, when serializing a field, manually masks the "repeated", "required", and "packed" bits to get the "base type" of the field. However it also needs to mask the "map" bit as the function to map the "base type" to an array index (`_valueTypeIndex`) only works for values that are a power of 2, i.e. there needs to be at most one bit set. This code still works today because of the special case when the map bit set, after getting the base type incorrectly. In other words, when the map bit is set we compute the wire type incorrectly, but we don't use the incorrect value. Changed in this PR: 1. `_valueTypeIndex` now has an assertion checking that the argument is really a power of 2. 2. `valueType` is now computed using `PbFieldType._baseType`, which correctly masks the "map" bit. 3. `wireFormat` is moved after the special case that checks for the map bit. With (1) tests in protoc_compiler start to fail. Either one of (2) or (3) fixes the issue, but I think both are improvements. JSON serializers correctly use the `PbFieldType._baseType` function to get the base type so no changes needed.
Protocol Buffers (protobuf) are Google's language-neutral, platform-neutral, extensible mechanism for serializing structured data.
This repository is home to packages related to protobuf for Dart. It contains: