When building with THREADING_IMPLEMENTED and passing the TLSH_OPTION_THREADED to Tlsh::final, the library will spawn two threads to do the calculation (see src/tlsh_impl.cpp)
std::thread t1(thread1);
std::thread t2(thread2);
But it passes arguments to those threads via globals:
static struct raw_args call1;
static struct raw_args call2;
void thread1()
{
raw_fast_update5_nochecksum( &call1 );
}
...
This is not safe in the case when the library user themself has multiple threads and is calling final simultaneously. The state will get silently corrupted, and the wrong hash value may result.
So we should either:
- Move those globals to the stack and pass them to the threads in the standard way
- Add locking (not recommended)
When building with
THREADING_IMPLEMENTEDand passing theTLSH_OPTION_THREADEDtoTlsh::final, the library will spawn two threads to do the calculation (see src/tlsh_impl.cpp)But it passes arguments to those threads via globals:
This is not safe in the case when the library user themself has multiple threads and is calling final simultaneously. The state will get silently corrupted, and the wrong hash value may result.
So we should either: