Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tidb_query_vec_executors: Fixed stack-borrowing undefined-behavior #7709

Merged
merged 3 commits into from
Apr 30, 2020

Commits on Apr 30, 2020

  1. tidb_query_vec_executors: Fixed stack-borrowing undefined-behavior

    I don't understand the stacked borrowing rules enough to understand why the
    existing code is a violation. It is creating a mutable unsafe pointer; then
    taking some immutable borrows to the same data while doing nothing with that
    pointer; then later using the pointer.
    
    Simply moving the creation of the unsafe pointer to immediately before it
    is used removes the error.
    
    Found with miri, which reports:
    
    ```
    error: Undefined Behavior: trying to reborrow for SharedReadOnly, but parent tag <1121039> does not have an appropriate item in the borrow sta
    ck
       --> components/tidb_query_vec_executors/src/slow_hash_aggr_executor.rs:281:32
        |
    281 |             let offset_begin = self.group_key_buffer.len();
        |                                ^^^^^^^^^^^^^^^^^^^^^ trying to reborrow for SharedReadOnly, but parent tag <1121039> does not have an ap
    propriate item in the borrow stack
        |
        = help: this indicates a potential bug in the program: it performed an invalid operation, but the rules it violated are still experimental
        = help: see https://github.com/rust-lang/unsafe-code-guidelines/blob/master/wip/stacked-borrows.md for further information
    ```
    
    Signed-off-by: Brian Anderson <[email protected]>
    brson committed Apr 30, 2020
    Configuration menu
    Copy the full SHA
    ff6b8bf View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    9ce05ff View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    f07201d View commit details
    Browse the repository at this point in the history