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

hs_compile_lit_multi ASAN failure for empty patterns #302

Closed
danlark1 opened this issue Feb 27, 2021 · 2 comments
Closed

hs_compile_lit_multi ASAN failure for empty patterns #302

danlark1 opened this issue Feb 27, 2021 · 2 comments

Comments

@danlark1
Copy link

danlark1 commented Feb 27, 2021

#undef NDEBUG
#include <hs.h>
#include <cassert>
/*
Explanation: ASAN segfault.
Version: 5.4.0
==160188==The signal is caused by a READ memory access.
    #0 0xee2e4d in ue2::setupFDRFloodControl(std::vector<ue2::hwlmLiteral, std::allocator<ue2::hwlmLiteral> > const&, ue2::EngineDescription const&, ue2::Grey const&) contrib/hyperscan/src/fdr/flood_compile.cpp:111:16
    #1 0xee62cd in ue2::(anonymous namespace)::TeddyCompiler::build() contrib/hyperscan/src/fdr/teddy_compile.cpp:570:23
    #2 0xee62cd in ue2::teddyBuildTable(ue2::HWLMProto const&, ue2::Grey const&) contrib/hyperscan/src/fdr/teddy_compile.cpp:658:15
    #3 0xec5257 in ue2::fdrBuildTableInternal(ue2::HWLMProto const&, ue2::Grey const&) contrib/hyperscan/src/fdr/fdr_compile.cpp:888:16
    #4 0xec5257 in ue2::fdrBuildTable(ue2::HWLMProto const&, ue2::Grey const&) contrib/hyperscan/src/fdr/fdr_compile.cpp:897:12
    #5 0xcb2eee in ue2::hwlmBuild(ue2::HWLMProto const&, ue2::CompileContext const&, unsigned long long) contrib/hyperscan/src/hwlm/hwlm_build.cpp:139:20
    #6 0xbb24b3 in ue2::buildHWLMMatcher(ue2::RoseBuildImpl const&, ue2::LitProto*) contrib/hyperscan/src/rose/rose_build_matchers.cpp:894:17
    #7 0xda5ef2 in ue2::RoseBuildImpl::buildFinalEngine(unsigned int) contrib/hyperscan/src/rose/rose_build_bytecode.cpp:3751:19
    #8 0xb6f1df in ue2::RoseBuildImpl::buildRose(unsigned int) contrib/hyperscan/src/rose/rose_build_compile.cpp:1796:12
    #9 0x4e2eaf in ue2::generateRoseEngine(ue2::NG&) contrib/hyperscan/src/compiler/compiler.cpp:436:26
    #10 0x4e2eaf in ue2::build(ue2::NG&, unsigned int*, unsigned char) contrib/hyperscan/src/compiler/compiler.cpp:509:17
    #11 0x4d6c2c in ue2::hs_compile_lit_multi_int(char const* const*, unsigned int const*, unsigned int const*, hs_expr_ext const* const*, unsigned long const*, unsigned int, unsigned int, hs_platform_info const*, hs_database**, hs_compile_error**, ue2::Grey const&) contrib/hyperscan/src/hs.cpp:379:35
    #12 0x4d87cb in hs_compile_lit_multi contrib/hyperscan/src/hs.cpp:484:12
    #13 0x4d0be9 in main hyperscan_bugs/empty_string_segfault.cpp:40:22
    #14 0x7fa13de90d09 in __libc_start_main csu/../csu/libc-start.c:308:16
    #15 0x4243c9 in _start (build_asan/hyperscan_bugs/empty_string_segfault+0x4243c9)
*/

int main() {
    hs_database_t *db = nullptr;
    hs_compile_error_t *compile_err = nullptr;
    // Haystack:
    const char* data = "\x00\x00\x00\x0a\x0a\x0a\x45\x45\x0a\x0a\x00\x00\x00";
    const size_t size = 13;
    // Patterns:
    const char *expr[] = {
        "",
        "\x73\x6f\x6d\x65\x20\x6e\x6f\x6e\x20\x65\x78\x69\x73\x74\x69\x6e\x67\x20\x73\x74\x72\x69\x6e\x67",
    };
    unsigned ids[] = {0, 1};
    size_t lens[] = {0, 24};
    unsigned flags[] = {HS_FLAG_CASELESS, HS_FLAG_SINGLEMATCH};
    hs_error_t err = hs_compile_lit_multi(expr, flags, ids, lens, sizeof(ids)/sizeof(*ids), HS_MODE_BLOCK, nullptr, &db, &compile_err);

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

    hs_free_database(db);
}
@Nor7th
Copy link

Nor7th commented Mar 9, 2021

Thanks for reporting the issue. Will fix it in next release.

@hongyang7
Copy link
Contributor

Please refer to latest develop branch.

markos referenced this issue in VectorCamp/vectorscan Aug 29, 2022
markos referenced this issue in VectorCamp/vectorscan Aug 29, 2022
fatchanghao pushed a commit that referenced this issue Feb 15, 2023
fatchanghao pushed a commit that referenced this issue Feb 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants