Commit c6af837
committed
dd: limit the copy buffer to the copy count
`bsize` is the least common multiple of `ibs` and `obs`, which for
relatively prime block sizes is their product: `ibs=16384 obs=16383`
reserves 256 MiB of address space. With `count=1` at most one `ibs`
record will ever be read, so that reservation is pure waste and fails
outright under a modest `RLIMIT_AS`.
Size the initial allocation with `calc_loop_bsize`, the same function
the main loop already uses to shrink each read as the count runs out.
`calc_loop_bsize` also had to stop overflowing: `count` is a
user-supplied `u64`, so `rremain * ibs` panicked in debug and wrapped
to a bogus (tiny) buffer size in release for a large `count=`.
Saturate both the subtraction and the multiplication; the `cmp::min`
against `ideal_bsize` then keeps the result correct.
Taken over from uutils#13373 by relative23; rebased onto the `AlignedBuf`
read scratch, with the count overflow fixed inside `calc_loop_bsize`
rather than guarded at the one call site.1 parent 1a6fb19 commit c6af837
2 files changed
Lines changed: 31 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1231 | 1231 | | |
1232 | 1232 | | |
1233 | 1233 | | |
| 1234 | + | |
| 1235 | + | |
| 1236 | + | |
| 1237 | + | |
| 1238 | + | |
| 1239 | + | |
1234 | 1240 | | |
1235 | 1241 | | |
1236 | 1242 | | |
| |||
1486 | 1492 | | |
1487 | 1493 | | |
1488 | 1494 | | |
1489 | | - | |
1490 | | - | |
| 1495 | + | |
| 1496 | + | |
| 1497 | + | |
| 1498 | + | |
1491 | 1499 | | |
1492 | 1500 | | |
1493 | 1501 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
133 | 133 | | |
134 | 134 | | |
135 | 135 | | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
136 | 157 | | |
137 | 158 | | |
138 | 159 | | |
| |||
0 commit comments