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

SIGSEGV when using ffi.string with char[?] VLA #134

Closed
piotrp opened this issue Oct 15, 2021 · 3 comments
Closed

SIGSEGV when using ffi.string with char[?] VLA #134

piotrp opened this issue Oct 15, 2021 · 3 comments

Comments

@piotrp
Copy link

piotrp commented Oct 15, 2021

Reproduction case:

  1. Save as ffi_sigsegv.lua
local ffi = require "ffi"
local t_char = ffi.typeof("char[?]")

for i = 1, 10000 do
  local str = "abc" .. i .. "bca"
  print(i)
  ffi.string(t_char(#str, str), 1)
end

print("ok")
  1. Run docker run --rm -it -v "$(pwd):/work" openresty/openresty:1.19.9.1-buster-fat bash -c 'resty /work/ffi_sigsegv.lua; echo $?'

Run a few times if it prints "ok", on my system it's failing nine times out of ten. I tried running it via luajit but then I didn't manage to make it crash.

@piotrp piotrp closed this as completed Oct 15, 2021
@piotrp
Copy link
Author

piotrp commented Oct 15, 2021

Maybe LuaJIT tries to initialize my array with entirety of passed data, i.e. all characters of string str + implicit 0x0 to terminate it? But that shouldn't be the case.

@piotrp piotrp reopened this Oct 15, 2021
@doujiang24
Copy link
Member

Interesting, I do think it is a bug.

@doujiang24
Copy link
Member

i.e. all characters of string str + implicit 0x0 to terminate it?

Yes, you are right. It's indeed the behaviour of the official LuaJIT.

I found the source code here:
https://github.com/LuaJIT/LuaJIT/blob/v2.1/src/lj_cconv.c#L591

I have created a issue in official LuaJIT repo: LuaJIT/LuaJIT#758
So, closing this issue.

Thanks for your report, it's interesting anyway.

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

2 participants