Commit df3c3a1
Merge pull request from GHSA-c827-hfw6-qwvm
* Fix `rustix::fs::Dir` to avoid unbounded buffer growth.
Fix `Dir`'s buffer size computation to avoid resizing past a fixed
upper limit. This prevents it from growing without bound, such as in
the case of `Dir::rewind` for repeated iterations with the same `Dir`.
* Don't let `Dir` continue to try to iterate after a failure.
* Handle `io::Errno::INTR` gracefully.
* Write a more detailed comment on the buffer growth policy.
* Also mention that no buffer can ever be big enough for everything.
* Add tests against over-allocation & stuck iterator
* Rm `dir_iterator_does_not_overallocate` unit test in favour of docs
* Extend `test_dir` to cover `rewind`.
* Consistently handle directory removal as ending the stream.
libc implementations of directory iteration handle directory removal
by just ending the stream. In the linux_raw backend, this looks like
`ENOENT` from `getdents64`, so change the code to check for `ENOENT`
and end the stream.
This requires changing the `dir_iterator_does_not_get_stuck_on_io_error`
test to no longer expect a failure, so it's now renamed to
`dir_iterator_handles_dir_removal`.
To test the error case, add a new `dir_iterator_handles_io_errors`
test which uses `dup2` to induce an error, in both the linux_raw and
libc backends.
This exposes the fact that the libc `Dir` implementation was also
assuming that users would stop iterating after hitting a failure, so
add a `any_errors` flag to the libc backend as well.
* Add a test for removing the directory after doing `read_from`.
* In the libc backend, handle `ENOENT` when opening ".".
---------
Co-authored-by: cyqsimon <[email protected]>1 parent b78aeff commit df3c3a1
3 files changed
+224
-26
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
32 | | - | |
33 | | - | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
34 | 39 | | |
35 | 40 | | |
36 | 41 | | |
| |||
42 | 47 | | |
43 | 48 | | |
44 | 49 | | |
| 50 | + | |
| 51 | + | |
45 | 52 | | |
46 | 53 | | |
47 | 54 | | |
48 | 55 | | |
49 | 56 | | |
50 | 57 | | |
51 | | - | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
52 | 69 | | |
53 | 70 | | |
54 | 71 | | |
55 | 72 | | |
56 | 73 | | |
57 | 74 | | |
58 | | - | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
59 | 79 | | |
60 | 80 | | |
61 | 81 | | |
| |||
67 | 87 | | |
68 | 88 | | |
69 | 89 | | |
70 | | - | |
| 90 | + | |
| 91 | + | |
71 | 92 | | |
72 | 93 | | |
73 | 94 | | |
74 | 95 | | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
75 | 101 | | |
76 | | - | |
| 102 | + | |
77 | 103 | | |
78 | 104 | | |
79 | 105 | | |
80 | 106 | | |
81 | 107 | | |
82 | 108 | | |
83 | 109 | | |
| 110 | + | |
84 | 111 | | |
85 | 112 | | |
86 | 113 | | |
| |||
114 | 141 | | |
115 | 142 | | |
116 | 143 | | |
117 | | - | |
| 144 | + | |
118 | 145 | | |
119 | 146 | | |
120 | 147 | | |
| |||
127 | 154 | | |
128 | 155 | | |
129 | 156 | | |
130 | | - | |
| 157 | + | |
131 | 158 | | |
132 | 159 | | |
133 | 160 | | |
134 | 161 | | |
135 | 162 | | |
136 | 163 | | |
137 | | - | |
| 164 | + | |
138 | 165 | | |
139 | 166 | | |
140 | 167 | | |
141 | 168 | | |
142 | 169 | | |
143 | 170 | | |
144 | | - | |
| 171 | + | |
145 | 172 | | |
146 | 173 | | |
147 | 174 | | |
| |||
154 | 181 | | |
155 | 182 | | |
156 | 183 | | |
157 | | - | |
| 184 | + | |
158 | 185 | | |
159 | 186 | | |
160 | 187 | | |
| |||
170 | 197 | | |
171 | 198 | | |
172 | 199 | | |
173 | | - | |
| 200 | + | |
174 | 201 | | |
175 | 202 | | |
176 | 203 | | |
| |||
282 | 309 | | |
283 | 310 | | |
284 | 311 | | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
20 | 27 | | |
| 28 | + | |
| 29 | + | |
21 | 30 | | |
22 | | - | |
23 | 31 | | |
24 | 32 | | |
25 | 33 | | |
| |||
37 | 45 | | |
38 | 46 | | |
39 | 47 | | |
| 48 | + | |
| 49 | + | |
40 | 50 | | |
41 | 51 | | |
42 | | - | |
43 | 52 | | |
44 | 53 | | |
45 | 54 | | |
46 | 55 | | |
47 | 56 | | |
48 | 57 | | |
| 58 | + | |
| 59 | + | |
49 | 60 | | |
50 | | - | |
51 | 61 | | |
52 | 62 | | |
53 | 63 | | |
54 | 64 | | |
55 | | - | |
56 | | - | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
57 | 76 | | |
58 | | - | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
59 | 81 | | |
60 | 82 | | |
61 | 83 | | |
| |||
77 | 99 | | |
78 | 100 | | |
79 | 101 | | |
80 | | - | |
| 102 | + | |
81 | 103 | | |
82 | 104 | | |
83 | 105 | | |
| |||
135 | 157 | | |
136 | 158 | | |
137 | 159 | | |
138 | | - | |
139 | | - | |
140 | | - | |
141 | | - | |
142 | | - | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
143 | 178 | | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
144 | 183 | | |
145 | | - | |
| 184 | + | |
146 | 185 | | |
147 | 186 | | |
148 | 187 | | |
| |||
222 | 261 | | |
223 | 262 | | |
224 | 263 | | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
0 commit comments