zot / microfts

Small and fast FTS (full text search)
MIT License
32 stars 3 forks source link

runtime error on certain org files (minimal example included) #10

Closed rdicosmo closed 3 years ago

rdicosmo commented 3 years ago

I get a runtime error on certain org files. A minimal org file that shows the error is the following:

+STARTUP: hidestars

And here is the backtrace

$ ./microfts input -org /tmp/db.db /tmp/a.org panic: runtime error: slice bounds out of range [1:0]

goroutine 1 [running]: main.orgPart(0x24, 0xc000020180, 0x2b, 0x23, 0xc00002019f, 0x4) /home/dicosmo/code/microfts/fulltext.go:144 +0x5cf main.forParts(0xc000020180, 0x2b, 0xc000143bc0) /home/dicosmo/code/microfts/fulltext.go:108 +0xf7 main.(lmdbConfigStruct).indexOrg(0x665de0, 0x7ffceb819254, 0xa) /home/dicosmo/code/microfts/fts-lmdb.go:554 +0x18f main.(lmdbConfigStruct).index(0x665de0, 0x7ffceb819254, 0xa) /home/dicosmo/code/microfts/fts-lmdb.go:527 +0x48 main.cmdInput.func1() /home/dicosmo/code/microfts/fts-lmdb.go:518 +0x4f main.(lmdbConfigStruct).update.func1.1() /home/dicosmo/code/microfts/fts-lmdb.go:1682 +0x2f main.(lmdbConfigStruct).runTxn(0x665de0, 0xc00002cc40, 0x0, 0xc000143d08) /home/dicosmo/code/microfts/fts-lmdb.go:1720 +0x1d0 main.(lmdbConfigStruct).update.func1(0xc00002cc40, 0xc00002cc40, 0x0) /home/dicosmo/code/microfts/fts-lmdb.go:1681 +0x72 github.com/AskAlexSharov/lmdb-go/lmdb.(Txn).runOpTerm(0xc00002cc40, 0xc000143df0, 0x0, 0x0) /home/dicosmo/go/pkg/mod/github.com/!ask!alex!sharov/lmdb-go@v1.9.1/lmdb/txn.go:158 +0x6e github.com/AskAlexSharov/lmdb-go/lmdb.(Env).run(0xc00007a6f0, 0x1, 0x0, 0xc000143df0, 0x0, 0x0) /home/dicosmo/go/pkg/mod/github.com/!ask!alex!sharov/lmdb-go@v1.9.1/lmdb/env.go:515 +0xbb github.com/AskAlexSharov/lmdb-go/lmdb.(Env).Update(...) /home/dicosmo/go/pkg/mod/github.com/!ask!alex!sharov/lmdb-go@v1.9.1/lmdb/env.go:482 main.(*lmdbConfigStruct).update(0x665de0, 0xc000143e70) /home/dicosmo/code/microfts/fts-lmdb.go:1680 +0x77 main.cmdInput(0x665de0) /home/dicosmo/code/microfts/fts-lmdb.go:516 +0x19e main.runLmdb(0xc000070180) /home/dicosmo/code/microfts/fts-lmdb.go:210 +0x3be main.main() /home/dicosmo/code/microfts/fulltext.go:357 +0xc6f

zot commented 3 years ago

Thanks for the detailed bug report! I'll take a look.

zot commented 3 years ago

Hmm, are you running on either Windows or a Mac, by any chance? I'm not getting an error on Linux and I wonder if this is a line-end problem...

zot commented 3 years ago

Although I can't reproduce the error, I added a check that should handle it. I also compiled and uploaded new versions for Linux and Windows. Unfortunately I can't build it for the the Mac so I'll have to wait until someone can do that for me.

If you use Linux or Windows, would you mind testing the version I uploaded (or you can fetch it from the repo and build it, if you like).

rdicosmo commented 3 years ago

Thanks for looking into this so quickly: after recompilation, the error appears to have gone :-)

Here is more information that may help anyway.

I am on Linux (Debian bullseye).

$ go version go version go1.15.5 linux/amd64

Compilation raises several warnings:

$ go build -o microfts mdb.c: In function ‘mdb_cursor_put’: mdb.c:6779:9: warning: this statement may fall through [-Wimplicit-fallthrough=] 6779 | if (SIZELEFT(fp) < offset) { | ^ mdb.c:6784:5: note: here 6784 | case MDB_CURRENT: | ^~~~ mdb.c: In function ‘mdb_env_cwalk’: mdb.c:9216:7: warning: writing 8 bytes into a region of size 1 [-Wstringop-overflow=] 9216 | memcpy(NODEDATA(ni), &my->mc_next_pgno, sizeof(pgno_t)); | ^~~~~~~~~~~~~~~ mdb.c:916:8: note: at offset 0 to object ‘mn_data’ with size 1 declared here 916 | char mn_data[1]; /*< key and data are appended here / | ^~~ mdb.c: In function ‘mdb_node_add’: mdb.c:7367:4: warning: writing 8 bytes into a region of size 1 [-Wstringop-overflow=] 7367 | memcpy(ndata, &ofp->mp_pgno, sizeof(pgno_t)); | ^~~~~~~~~~~~ mdb.c:7361:5: warning: writing 8 bytes into a region of size 1 [-Wstringop-overflow=] 7361 | memcpy(ndata, data->mv_data, sizeof(pgno_t)); | ^~~~~~~~~~~~

zot commented 3 years ago

Great! It's the holidays here so I have some time to mess around with this stuff :).

Yeah, those errors are from the C code included with lmdb-go. I haven't looked at how to address those.