Skip to content

lua struct.unpack redis segfault #901

Closed

Description

@bjne

This lua script causes redis (atleast 2.6.9) to segfault:

local t={}; for i=1,288 do t[i]=0 end
redis.call("SET", KEYS[1], struct.pack(("H"):rep(288), unpack(t)))
t = struct.unpack(("H"):rep(288), redis.call("GET", KEYS[1]))

Activity

  1. bjne commented on Jan 22, 2013

    @bjne
    Author

    Program received signal SIGSEGV, Segmentation fault.
    0x00007ffff744f7d0 in _int_malloc (av=0x7ffff7738e40, bytes=129)
    at malloc.c:4496
    4496 malloc.c: No such file or directory.
    in malloc.c
    (gdb) bt
    #0 0x00007ffff744f7d0 in _int_malloc (av=0x7ffff7738e40, bytes=129)
    at malloc.c:4496
    #1 0x00007ffff74527f6 in _int_realloc (av=0x7ffff7738e40,
    oldp=0x6ecbc0, oldsize=80, nb=144) at malloc.c:5274
    #2 0x00007ffff7452d40 in *_GI___libc_realloc (oldmem=0x6ecbd0,
    bytes=128) at malloc.c:3822
    #3 0x000000000045741c in luaM_realloc
    ()
    #4 0x000000000045b6c8 in setarrayvector ()
    #5 0x000000000045bfdd in resize ()
    #6 0x000000000045bd43 in newkey ()
    #7 0x000000000045cf95 in luaV_settable ()
    #8 0x000000000045dfb9 in luaV_execute ()
    #9 0x000000000045561d in luaD_call ()
    #10 0x0000000000454cf7 in luaD_rawrunprotected ()
    #11 0x0000000000454d72 in luaD_pcall ()
    #12 0x000000000045249f in lua_pcall ()
    #13 0x0000000000444b19 in evalGenericCommand (c=0x7ffff5080000,
    evalsha=0) at scripting.c:872
    #14 0x000000000041b60b in call (c=0x7ffff5080000, flags=7)
    at redis.c:1502
    #15 0x000000000041babd in processCommand (c=0x7ffff5080000)
    at redis.c:1677
    #16 0x000000000042641f in processInputBuffer (c=0x7ffff5080000)
    at networking.c:1011
    #17 0x0000000000426533 in readQueryFromClient (
    el=, fd=7, privdata=,
    mask=) at networking.c:1074
    #18 0x000000000041767c in aeProcessEvents (eventLoop=0x7ffff6855150,
    flags=) at ae.c:382
    #19 0x000000000041793b in aeMain (eventLoop=0x7ffff6855150) at ae.c:425
    #20 0x000000000041dc1f in main (argc=1, argv=0x7fffffffeba8)
    at redis.c:2622

  2. antirez commented on Jan 22, 2013

    @antirez
    Contributor

    Thank you for reporting, fixing ASAP.

  3. charsyam commented on Jan 23, 2013

    @charsyam
    Contributor

    Hi, @bjne, How can I reproduce it?

    I tried it but I can't reproduce. Thank you.

  4. bjne commented on Jan 23, 2013

    @bjne
    Author

    save script to file,

    redis-cli --eval script somevarname

    Might have to run it couple times

  5. antirez commented on Jan 23, 2013

    @antirez
    Contributor

    Hello, confirmed, there is a bug here, fixing ASAP, thank you for reporting.

  6. antirez commented on Jan 23, 2013

    @antirez
    Contributor

    It Was Not My Code (TM)

    The Lua struct library was to blame, I updated the code to latest version of the lib and it seems to be fixed.

    Closing the issue but I'll appreciate a feedback after the upgrade (however I tested it manually and via valgrind on two systems).

    Thanks again for reporting!

  7. added a commit that references this issue on Oct 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions