Fix uncontrolled resource consumption in ReadType deserializers. - #258
Open
copybara-service[bot] wants to merge 1 commit into
Open
Fix uncontrolled resource consumption in ReadType deserializers.#258copybara-service[bot] wants to merge 1 commit into
copybara-service[bot] wants to merge 1 commit into
Conversation
copybara-service
Bot
force-pushed
the
copybara/952351025
branch
from
July 22, 2026 23:00
3ff63ba to
f51a60e
Compare
When deserializing strings, vectors, or containers via `ReadType`, unvalidated 32-bit and 64-bit size headers could trigger excessive memory allocations (std::bad_alloc) or denial of service before verifying stream bounds. Addresses [CWE-400: Uncontrolled Resource Consumption](https://cwe.mitre.org/data/definitions/400.html) and [CWE-770: Allocation of Resources Without Limits or Throttling](https://cwe.mitre.org/data/definitions/770.html). * Add ValidateReadSize helper as a public API requiring an explicit `max_non_seekable_read parameter` (with `kDefaultMaxNonSeekableRead` defined as 512 MiB) to verify requested allocation against remaining stream length for seekable streams and enforce sanity caps for non-seekable streams. * Bound initial container reservations in `ReadContainerType` to prevent OOM on malformed count headers. * Added unit tests verifying clean failure on oversized and negative read attempts, including direct usage of `ValidateReadSize` and custom non-seekable stream limits. PiperOrigin-RevId: 952351025
copybara-service
Bot
force-pushed
the
copybara/952351025
branch
from
July 27, 2026 11:23
f51a60e to
2539c0c
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix uncontrolled resource consumption in ReadType deserializers.
When deserializing strings, vectors, or containers via
ReadType, unvalidated 32-bit and 64-bit size headers could trigger excessive memory allocations (std::bad_alloc) or denial of service before verifying stream bounds.Addresses CWE-400: Uncontrolled Resource Consumption and CWE-770: Allocation of Resources Without Limits or Throttling.
max_non_seekable_read parameter(withkDefaultMaxNonSeekableReaddefined as 512 MiB) to verify requested allocation against remaining stream length for seekable streams and enforce sanity caps for non-seekable streams.ReadContainerTypeto prevent OOM on malformed count headers.ValidateReadSizeand custom non-seekable stream limits.