lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Wed, Jan 30, 2019 at 4:58 AM Sean Conner <sean@conman.org> wrote:
>
>
>   I managed to generate a segfault with LPEG and I can reproduce the issue
> with this code [1]:
>
> local lpeg = require "lpeg"
> local Cg = lpeg.Cg
> local Cc = lpeg.Cc
> local Cb = lpeg.Cb
> local P  = lpeg.P
>
> local cnt = Cg(Cc(0),'count')
>           * (P(1) * Cg(Cb'count' / function(c) return c + 1 end,'count'))^0
>           * Cb'count'
>
> print(cnt:match(string.rep("x",512+128))) -- CRASH at some point past this line

LuLPeg also crashes, but for a larger string (between 512 * 51 and 512
* 52 with Lua 5.3).

Just in case, your problem can be solved with a folding capture and no
temp Lua variable:

    local cnt = Cf(
      Cp() * P(1)^0 * Cp(),
      function(first, last) return last - first end
    )

—Pierre-Yves