fix(iter): Fix Unsoundness in Filter/FilterMap::next_chunk#153813
fix(iter): Fix Unsoundness in Filter/FilterMap::next_chunk#153813TKanX wants to merge 1 commit intorust-lang:mainfrom
Filter/FilterMap::next_chunk#153813Conversation
Filter/FilterMap::next_chunkFilter/FilterMap::next_chunk
|
r? @scottmcm rustbot has assigned @scottmcm. Use Why was this reviewer chosen?The reviewer was selected based on:
|
This comment has been minimized.
This comment has been minimized.
|
Would it be better to panic in the case of a buggy |
|
you could also write a "manual" try_for_each instead, with a try { } block and a for loop |
Yes! |
674a6cd to
088a316
Compare
|
@KyleDavidE Thanks! |
|
Another option would be to switch to using |
Does this approach still hold when the |
This comment has been minimized.
This comment has been minimized.
I'm pretty sure. https://doc.rust-lang.org/std/mem/fn.conjure_zst.html Conjuring a zst in a way that breaks library invarents is not allowed. |
…hunk` Co-authored-by: Kyle Ehrlich <4015993+KyleDavidE@users.noreply.github.com>
088a316 to
eacacdc
Compare
|
r? @the8472 |
Summary:
2 unsoundness bugs in
next_chunk_dropless/FilterMap::next_chunk: (1) N=0 triggers an out-of-bounds unsafe write before any bounds check; (2) a safetry_for_eachcan legally ignoreControlFlow::Break, writing past the array end.Relates #98326
This fix is simple add defensive checks. If any better way please let me know.Fix: add an
if N == 0early return, andpanic!whenidx >= Ninside the closure.Closes #153803