Skip to content

v4.7.4: Apply allocation limit consistently on input archives

Choose a tag to compare

@eyalz800 eyalz800 released this 09 Aug 21:02
· 3 commits to main since this release
The allocation limit was only consulted on some of the paths that turn a
number read from the archive into an allocation. Make the handling uniform:

* Associative containers (`std::map`, `std::set`, `std::unordered_map`,
  `std::unordered_set`, ...) read an element count and then insert that many
  elements, which previously ignored the configured allocation limit
  entirely. The count is now checked against the limit the same way a
  resizable container's size prefix is.

* Length delimited protobuf fields whose element type is not fundamental
  take a `reserve()` path that did not consult the allocation limit at all.
  The limit check now covers both the `resize()` and the `reserve()` path.

* Bound the variant alternative index with `>=` rather than `>`. The extra
  value was not reachable, since an unrecognised id already resolves to
  `size_t(-1)`, but the bound was off by one.

Tests cover each container kind at and beyond the limit, both protobuf paths
with a limit configured, that a message with no limit configured is
unaffected, and that valid messages still round trip. The protobuf tests use
a recording allocator so they distinguish rejecting the input up front from
allocating first and failing afterwards.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Dn1bSVJQe33FQ7uBGZpewf