Skip to content

Threaded TLSH calculation code is not reentrant #167

Description

@Zenchreal

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions