intel / hyperscan

High-performance regular expression matching library
https://www.hyperscan.io
Other
4.83k stars 721 forks source link

Deadloop in roseRunProgram_l. hyperscan/src/rose/program_runtime.c:3055: roseRunProgram_l: Assertion `0' failed. #141

Closed danlark1 closed 5 years ago

danlark1 commented 5 years ago

Hi, here is one of the programs to reproduce such behavior.

#include <hs.h>
#include <cassert>
#include <string>

int main() {
    hs_database_t *db = nullptr;
    hs_compile_error_t *compile_err = nullptr;
    std::string data = "/odezhda-dlya-bega/";
    const char *expr[] = {"/odezhda-dlya-bega/", "kurtki-i-vetrovki-dlya-bega", "futbolki-i-mayki-dlya-bega"};
    unsigned flags[] = {HS_FLAG_DOTALL | HS_FLAG_SINGLEMATCH, HS_FLAG_DOTALL | HS_FLAG_SINGLEMATCH, HS_FLAG_DOTALL | HS_FLAG_SINGLEMATCH};
    hs_error_t err = hs_compile_multi(expr, flags, nullptr, 3, HS_MODE_BLOCK, nullptr, &db, &compile_err);

    assert(HS_SUCCESS == err);
    assert(db != nullptr);

    hs_scratch_t *scratch = nullptr;
    err = hs_alloc_scratch(db, &scratch);
    assert(HS_SUCCESS == err);
    assert(scratch != nullptr);

    err = hs_scan(db, data.c_str(), data.size(), 0, scratch, nullptr, nullptr);
    assert(HS_SUCCESS == err);

    hs_free_database(db);
    err = hs_free_scratch(scratch);
    assert(HS_SUCCESS == err);
}

https://pastebin.com/YWgd2H3R

I am using the trunk version of hyperscan, in 4.7 this code does not go into the deadloop.

This issue was discovered while adding hyperscan to the open-source database system ClickHouse.

xiangwang1 commented 5 years ago

Hi, thanks for reporting this issue.

I think this is related to calling hs_compile_multi() without specifying ids for your patterns. It only happens in release 5.1. We'll take a look and try to fix it.

danlark1 commented 5 years ago

Seems to be fixed in 5.1.1. Thank you