romgrk / fzy-lua-native

Luajit FFI bindings to FZY
116 stars 15 forks source link

SIGSEGV (Address boundary error) #27

Open xsh005 opened 8 months ago

xsh005 commented 8 months ago

tldr:

local fzy = require("fzy")
fzy.filter("foo", { string.rep(" ", 1039) })
-- 1039 and below: no problem
-- 1040/1041: LuaJIT ASSERT lj_api.c:162: lua_settop: bad stack slot -2
-- fish: Job 1, 'nvim -l test.lua' terminated by signal SIGABRT (Abort)
-- 1042 and above: fish: Job 1, 'nvim -l test.lua' terminated by signal SIGSEGV (Address boundary error)
long story: Hello! I am experimenting with this library and implementing a fuzzy finder frontend. When I was testing on [a big repo](https://github.com/ghc/ghc), I noticed that my little script segfault-ed. I am able to narrow the problem down to one file: My setup: ``` -rw-r--r--. 1 xiaoshihou xiaoshihou 205 Jan 20 16:10 fzy.lua -rwxr-xr-x. 1 xiaoshihou xiaoshihou 29688 Jan 20 16:10 fzy_native.so -rw-r--r--. 1 xiaoshihou xiaoshihou 337 Jan 20 16:23 test.lua -rw-r--r--. 1 xiaoshihou xiaoshihou 158538 Jan 20 16:20 test.txt ``` test.txt is [this file here](https://github.com/ghc/ghc/blob/5b0392e062b1e73adccdb99f9057d15375ed793a/libraries/base/src/GHC/IO/Encoding/CodePage/Table.hs) test.lua: ```lua local fzy = require("fzy") local uv = vim.uv local path = "/tmp/test.txt" local fd = assert(uv.fs_open(path, "r", 438)) local stat = assert(uv.fs_fstat(fd)) local data = assert(uv.fs_read(fd, stat.size, 0)) assert(uv.fs_close(fd)) data = vim.split(data, "\n") -- this outputs fine if I print it fzy.filter("ex", data) ``` Then: ``` ❯ nvim -l test.lua fish: Job 1, 'nvim -l test.lua' terminated by signal SIGSEGV (Address boundary error) ``` I know there's a bunch of horrible `\xc0` stuff in the file, but that shouldn't make fzy segfault :thinking: Thank you for your time!
xsh005 commented 8 months ago

update: this particular line would segfault

     decoderArray = ConvArray "\x0\x0\x1\x0\x2\x0\x3\x0\x9c\x0\x9\x0\x86\x0\x7f\x0\x97\x0\x8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0\x78\x0\x79\x0\x7a\x0\xa1\x0\xbf\x0\xd0\x0\xdd\x0\xde\x0\xae\x0\x5e\x0\xa3\x0\xa5\x0\xb7\x0\xa9\x0\xa7\x0\xb6\x0\xbc\x0\xbd\x0\xbe\x0\x5b\x0\x5d\x0\xaf\x0\xa8\x0\xb4\x0\xd7\x0\x7b\x0\x41\x0\x42\x0\x43\x0\x44\x0\x45\x0\x46\x0\x47\x0\x48\x0\x49\x0\xad\x0\xf4\x0\xf6\x0\xf2\x0\xf3\x0\xf5\x0\x7d\x0\x4a\x0\x4b\x0\x4c\x0\x4d\x0\x4e\x0\x4f\x0\x50\x0\x51\x0\x52\x0\xb9\x0\xfb\x0\xfc\x0\xf9\x0\xfa\x0\xff\x0\x5c\x0\xf7\x0\x53\x0\x54\x0\x55\x0\x56\x0\x57\x0\x58\x0\x59\x0\x5a\x0\xb2\x0\xd4\x0\xd6\x0\xd2\x0\xd3\x0\xd5\x0\x30\x0\x31\x0\x32\x0\x33\x0\x34\x0\x35\x0\x36\x0\x37\x0\x38\x0\x39\x0\xb3\x0\xdb\x0\xdc\x0\xd9\x0\xda\x0\x9f\x0"#
local fzy = require("fzy")
local str =
[[     decoderArray = ConvArray "\x0\x0\x1\x0\x2\x0\x3\x0\x9c\x0\x9\x0\x86\x0\x7f\x0\x97\x0\x8d\x0\x8e\x0\xb\x0\xc\x0\xd\x0\xe\x0\xf\x0\x10\x0\x11\x0\x12\x0\x13\x0\x9d\x0\x85\x0\x8\x0\x87\x0\x18\x0\x19\x0\x92\x0\x8f\x0\x1c\x0\x1d\x0\x1e\x0\x1f\x0\x80\x0\x81\x0\x82\x0\x83\x0\x84\x0\xa\x0\x17\x0\x1b\x0\x88\x0\x89\x0\x8a\x0\x8b\x0\x8c\x0\x5\x0\x6\x0\x7\x0\x90\x0\x91\x0\x16\x0\x93\x0\x94\x0\x95\x0\x96\x0\x4\x0\x98\x0\x99\x0\x9a\x0\x9b\x0\x14\x0\x15\x0\x9e\x0\x1a\x0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