python-hyperscan icon indicating copy to clipboard operation
python-hyperscan copied to clipboard

dumpb/loadb results in non-working database

Open piotr-piatkowski opened this issue 1 year ago • 3 comments

I was trying to serialize and then restore database, all I get when trying to call scan on restored database is hyperscan.InvalidError: error code -1. I'm using python module version 0.7.7 and python 3.11.9.

Here's sample code:

    db = hyperscan.Database(mode=hyperscan.HS_MODE_BLOCK)
    db.compile(
        expressions=[b'bar']
    )

    def callback(id, start, end, flags, context):
        print(f"Matched {id} from {start} to {end}")

    db.scan(b'foo bar baz', callback)

    data = hyperscan.dumpb(db)
    db2 = hyperscan.loadb(data, hyperscan.HS_MODE_BLOCK)
    db2.scan(b'foo bar baz', callback)

And results:

        data = hyperscan.dumpb(db)
        db2 = hyperscan.loadb(data, hyperscan.HS_MODE_BLOCK)
>       db2.scan(b'foo bar baz', callback)
E       hyperscan.InvalidError: error code -1

I also noticed in debugger that restored db has no scratch atribute set (it's None), but I'm not sure if this is the reason.

piotr-piatkowski avatar Jun 06 '24 12:06 piotr-piatkowski