If a `HashMap` from `sgx_tstd` is created using `new` (or a `with_capacity` 
with a low value) it can only be inserted to a few times, after which it will 
segfault.

This is deeply concerning, and surprising (`HashMap` should survive this). As 
an immediate consequence, for instance, the provided `tlsserver` example only 
supports a few concurrent TLS sessions (because they are stored in a HashMap).

If it is created with `with_capacity`, some small values fail in the same 
fashion, after which it seems to be OK. However the minimum value to make this 
work seems to be contextual (!). This means that it may vary depending on the 
surrounding code (!).

Here's an example:
```rust
#![crate_name = "hashmap"]
#![crate_type = "staticlib"]
#![cfg_attr(not(target_env = "sgx"), no_std)]
#![cfg_attr(target_env = "sgx", feature(rustc_private))]

#[cfg(not(target_env = "sgx"))]
#[macro_use]
extern crate sgx_tstd as std;

use std::collections::HashMap;

#[no_mangle]
pub extern "C"
fn e_do() {
    let mut local_map = HashMap::with_capacity(2); // This could also be 
HashMap::new()

    for i in 0..1000 {
        local_map.insert(i, 42);
        eprintln!("l: inserted {}", i);
    }
}
```

On my machine, if the initial capacity is 8, it seems fine (but in some 
contexts, that capacity was lowered to 4, for some reason). It usually 
segfaults in a few (<20) insertions, but this is probably machine-dependant.



-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/apache/incubator-teaclave-sgx-sdk/issues/331

Reply via email to