Repository navigation
Do not pre-allocate memory for the declared array size when reading ZooKeeper protocol arrays - #126914
Conversation
The generic ZooKeeper array reader resized a `std::vector<T>` to the declared element count before reading any element. A tiny `Create` request declaring a huge ACL count forced a multi-GB zero-initialized allocation held while the socket stayed open. Grow the vector incrementally instead, reserving at most 4096 elements, so allocated memory tracks bytes actually read. Truncated input now throws on the first missing element after a bounded allocation. Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
Workflow [PR], commit [35e9ff8] Summary: ✅
AI ReviewSummaryThe PR bounds initial allocation when decoding ZooKeeper arrays and appends elements only after successfully reading them. The revised regression test directly checks the allocation bound, addressing the previous finding. No unresolved findings remain. Missing context / blind spots
Final VerdictStatus: ✅ Approve. No additional code changes requested; unit-test CI results remain pending. |
The truncated-input case only checked that reading throws, which the old `resize`-based reader also did after allocating the full declared count, so the test passed with the bug restored on a machine with enough memory. Name the reservation cap `MAX_ARRAY_PREALLOCATION`, declare twice that many ACLs in the test, and assert that `acls.capacity` stays within the cap after the exception. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units567 translation units recompiled, 4928 s compile time in total, 356 of them have a recent master baseline. Translation units without a recent master baseline:
|
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Cherry pick #126914 to 26.3: Do not pre-allocate memory for the declared array size when reading ZooKeeper protocol arrays
… array size when reading ZooKeeper protocol arrays
Cherry pick #126914 to 26.7: Do not pre-allocate memory for the declared array size when reading ZooKeeper protocol arrays
… array size when reading ZooKeeper protocol arrays
Backport #126914 to 26.10: Do not pre-allocate memory for the declared array size when reading ZooKeeper protocol arrays
Backport #126914 to 26.9: Do not pre-allocate memory for the declared array size when reading ZooKeeper protocol arrays
Backport #126914 to 26.8: Do not pre-allocate memory for the declared array size when reading ZooKeeper protocol arrays
Backport #126914 to 26.7: Do not pre-allocate memory for the declared array size when reading ZooKeeper protocol arrays
…e declared array size when reading ZooKeeper protocol arrays
Backport #126914 to 26.3: Do not pre-allocate memory for the declared array size when reading ZooKeeper protocol arrays
The generic ZooKeeper protocol array reader (
read(std::vector<T> &, ReadBuffer &)inZooKeeperIO.h) resized the vector to the element count declared in the request before reading any element. A small request (for example aCreatewith a large declared ACL count) caused Keeper to allocate and zero-initialize up to several GB of memory, even when the request had no matching data.The reader now grows the vector incrementally, with at most 4096 elements reserved up front. Allocated memory now follows the bytes that are actually read. Truncated input throws an exception on the first missing element after a small allocation.
A unit test in
gtest_coordination.cppcovers this case.Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Keeper no longer pre-allocates memory for the array size declared in a request (for example the ACL list in
Create) before it reads the array elements. Before this fix, a small malformed request could cause a large memory allocation.🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/126914]
Version info
26.11.1.519-master(included in26.11and later)26.10.2.78,26.9.25.15,26.8.34.13,26.7.37.12,26.3.60.2