DescriptionFix a use after free crasher in the ReadAsync task initiated on Windows by the FileStream::Context::Read operation.
The crash was reported by the DrMemory bot and based on the stack happens because the OVERLAPPED structure passed into
the ReadFile call is invalid.
Proposed fix is the following:-
1. Have two flags io_complete_for_read_received_ and async_read_completed_ which track whether the IO completion was
received for a Read and whether we received a notification on the calling thread that the ReadFile call returned.
We invoke the user callback only when both these flags are true.
2. We have another flag async_read_initiated_ which is set to true if an asynchonous Read was initated. We use this
to not set the async_in_progress_ flag to false until both notifications as per 1 above are received.
3. All flags above are reset when we invoke the user callback. That now happens in the InvokeUserCallback function.
4. We need to save the result in a member as the callback is invoked later.
5. Removed the Weak pointer member from the Context class as this is not needed because the Context instance should remain
valid until the pending Read operation completes.
BUG=455066
Committed: https://crrev.com/806016e8bf4e217f2ebe5ad052481699f2287c63
Cr-Commit-Position: refs/heads/master@{#315098}
Patch Set 1 #Patch Set 2 : Added comments for the InvokeUserCallback function #Patch Set 3 : Fixed trybot redness #
Total comments: 5
Patch Set 4 : Replaced the DCHECK for async_in_progress_ with a CHECK #
Total comments: 4
Patch Set 5 : Address review comments #Patch Set 6 : Fix ReadAsyncResult #Patch Set 7 : Fixed build error #
Total comments: 2
Patch Set 8 : Address review comments #
Total comments: 4
Patch Set 9 : Check ReadFile success and set error to 0 #Patch Set 10 : Fix build error #Patch Set 11 : Rebased to tip #
Messages
Total messages: 18 (5 generated)
|