Skip to content

fix: cap deserialization vector/map sizes at 256 MB to prevent OOM DoS#22283

Open
johnathan79717 wants to merge 1 commit intomerge-train/barretenbergfrom
jh/fix-serialize-unbounded-alloc
Open

fix: cap deserialization vector/map sizes at 256 MB to prevent OOM DoS#22283
johnathan79717 wants to merge 1 commit intomerge-train/barretenbergfrom
jh/fix-serialize-unbounded-alloc

Conversation

@johnathan79717
Copy link
Copy Markdown
Contributor

Summary

  • Add 256 MB byte-budget cap (MAX_SERIALIZE_BYTES) before every vector::resize() and map iteration in serialize.hpp
  • Prevents attacker-controlled uint32_t size fields from triggering multi-GB allocations that crash the process via OOM before any crypto validation
  • Matches the 256 MB cap already used for decompression in private_execution_steps.cpp

Fixes AztecProtocol/barretenberg-claude#2415

Protected paths

All 4 deserialization entry points that read a size from untrusted input:

  1. read(uint8_t const*&, vector<uint8_t>&) - raw pointer path
  2. read(istream&, vector<uint8_t>&) - stream path
  3. read(B&, vector<T, A>&) - generic vector path (checks size * sizeof(T))
  4. read(B&, map<T, U>&) - map path (checks size * (sizeof(T) + sizeof(U)))

Test plan

  • serialize-tests_tests passes (2/2)
  • CI green

An attacker-controlled uint32_t size field in binary deserialization
could trigger multi-GB allocations before any crypto validation.
Add bounds checks on all vector::resize() and map iteration paths
in serialize.hpp, matching the 256 MB cap used for decompression.

Fixes AztecProtocol/barretenberg-claude#2415
@johnathan79717 johnathan79717 added the ci-barretenberg Run all barretenberg/cpp checks. label Apr 2, 2026
@johnathan79717 johnathan79717 requested a review from ludamad April 2, 2026 16:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci-barretenberg Run all barretenberg/cpp checks.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants