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
{{ message }}
Repository navigation
tr: a large [c*n] repeat count is materialized unbounded — capacity overflow panic / allocation abort (exit 134) #14420
tr accepts any repeat count in the [c*n] construct up to u64::MAX, then eagerly materializes the repeat into a Vec<u8> — one byte per repetition. A count in the 10^14 range aborts the process with an allocation failure; a count at or above 2^63 aborts with a capacity overflow panic.
Steps to reproduce
$ tr '[a*9223372036854775808]' b </dev/nullthread 'main' panicked at library/alloc/src/raw_vec/mod.rs:28:5:capacity overflownote: run with `RUST_BACKTRACE=1` environment variable to display a backtraceAborted (core dumped)
$ echo$?134
$ tr '[a*99999999999999]' b </dev/nullmemory allocation of 99999999999999 bytes failedAborted (core dumped)
$ echo$?134
Root cause
Sequence::flatten expands a repeat into an iterator of n bytes:
The two consumers of that iterator fail in two different ways:
// src/uu/tr/src/operation.rs:295 -- SET1: allocates n bytes up frontletmut set1_solved:Vec<u8> = set1.iter().flat_map(Self::flatten).collect();// src/uu/tr/src/operation.rs:301-308 -- SET2: iterates n timeslet set2_len = set2
.iter().filter_map(|s| match s {Self::CharStar(_) => None,
r => Some(r),}).flat_map(Self::flatten).count();
collect() (SET1) — Box<dyn Iterator> forwards size_hint, and repeat_n reports it exactly, so Vec's SpecFromIterNested reserves all n bytes in one request. That is the abort.
Activity
tr: do not expand [c*n] repeats character by character