Skip to content

Fix uncontrolled resource consumption in ReadType deserializers. - #258

Open
copybara-service[bot] wants to merge 1 commit into
mainfrom
copybara/952351025
Open

Fix uncontrolled resource consumption in ReadType deserializers.#258
copybara-service[bot] wants to merge 1 commit into
mainfrom
copybara/952351025

Conversation

@copybara-service

Copy link
Copy Markdown

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.

  • 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.

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
copybara-service Bot force-pushed the copybara/952351025 branch from f51a60e to 2539c0c Compare July 27, 2026 11:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant