Avoid holding onto the buffer when parsing unknown length-delimited fields (#863)

Currently unknown field set parser stores length-delimited fields as
views of the input buffer. This has a few issues:

- It's inconsistent with the known-field parsing where we copy `bytes`
fields.

- A single unknown length-delimited field can cause keeping a large
input buffer alive.

- Because the caller is free to modify the input buffer, this
implementation does not allow freezing an unknown field set.

(This can also be fixed by copying the length-delimited fields when
freezing.)

- Even when the parsed message is not frozen, this aliasing can cause
bugs as it's not documented. Even if we document it, it would probably
be a footgun.

This can cause segfaults or worse when the input buffer is passed from
e.g. C++ or C as a `Uint8List`, and the caller frees the buffer after
parsing while the message is still in use.

This PR makes `readBytes` copy the bytes before returning to avoid
aliasing. A new member `readBytesAsView` added with the previous
behavior. Unknown length-delimited field parsing fixed with the new
`readBytes`.

Sync CL: cl/552077275
8 files changed
tree: 6709bc912ca0c849bc8bf4b1fe2b0da773f0fd7b
  1. .github/
  2. api_benchmark/
  3. benchmarks/
  4. protobuf/
  5. protoc_plugin/
  6. tool/
  7. .gitignore
  8. analysis_options.yaml
  9. AUTHORS
  10. LICENSE
  11. mono_repo.yaml
  12. README.md
README.md

CI status

Protobuf support for Dart

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.

PackageDescriptionPublished Version
protobufA support library for the generated codepub package
protoc_pluginA Dart back-end for the protoc compilerpub package
api_benchmarkBenchmarking for various API calls
query_benchmarkBenchmark for encoding and decoding of a “real-world” protobuf

Publishing automation

For information about our publishing automation and release process, see https://github.com/dart-lang/ecosystem/wiki/Publishing-automation.