You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Calling size_hint() on the returned iterator recurses through all 4096 levels via vtable dispatch (Chain::size_hint → Box<dyn Iterator>::size_hint → vtable → Chain::size_hint → ...), eventually causing a stack overflow.
Reproduction
RUSTFLAGS="-Zsanitizer=address" cargo +nightly test --target aarch64-apple-darwin --lib
The recursion depth equals BUCKETS, which at 4096 is deep enough to overflow even without ASAN on constrained stacks (e.g. signal handler stacks, threads with reduced stack size).
Fix
Replace the manual chaining loop with flat_map, which has O(1) stack depth:
Summary
HashCounter::iter()insrc/collector.rsbuilds a left-leaning chain of 4096 nestedBox<dyn Iterator>+Chainpairs — one per bucket (BUCKETS = 1 << 12 = 4096):Calling
size_hint()on the returned iterator recurses through all 4096 levels via vtable dispatch (Chain::size_hint→Box<dyn Iterator>::size_hint→ vtable →Chain::size_hint→ ...), eventually causing a stack overflow.Reproduction
ASAN reports:
The recursion depth equals
BUCKETS, which at 4096 is deep enough to overflow even without ASAN on constrained stacks (e.g. signal handler stacks, threads with reduced stack size).Fix
Replace the manual chaining loop with
flat_map, which has O(1) stack depth: