ludocode / msgpack-tools

Command-line tools for converting between MessagePack and JSON / msgpack.org[UNIX Shell]
Other
258 stars 18 forks source link

core dump #14

Open luinx opened 3 years ago

luinx commented 3 years ago

I was parsing a large msgpack file (sorry the file is confidential)

mpack breakpoint hit at /home/nick/code/msgpack-tools/contrib/mpack-df17e83f0fa8571b9cd0d8ccf38144fa90e244d1/src/mpack/mpack-common.c:322

ludocode commented 3 years ago

Hmm. The relevant line is here:

https://github.com/ludocode/mpack/blob/df17e83f0fa8571b9cd0d8ccf38144fa90e244d1/src/mpack/mpack-common.c#L322

This is hitting an assertion, which I guess means you're compiling in debug mode. This does look like a bug in the code, although what code I'm not sure. Could be in msgpack-tools (doubtful), in MPack (most likely) or in RapidJSON (unlikely considering how popular it is.) Do you have a stack trace? It would be really useful to help debug. The bug is likely happening in one of the lines in this range:

https://github.com/ludocode/msgpack-tools/blob/develop/src/json2msgpack.cpp#L180-L199

The assertion would be triggered in mpack_finish_map() or mpack_finish_array(). It would occur if RapidJSON gave us a different Size() or MemberCount() than the number of items in its iterator, or if MPack has some bug in its tracking code.

It's possible it's already been fixed upstream. msgpack-tools is currently built with a fairly old version of both MPack and RapidJSON. I'll try to upgrade it sometime soon.

the-vampiire commented 2 years ago

getting the same error. my data is public (algorand block data) so i can share here. could very well be user error - i have not worked with msgpack before and came across your tool in hopes of decoding it.

hope this helps.

source data

curl https://algoexplorerapi.io/v2/blocks/18174030\?format\=msgpack -s > msgpack-18174030

equivalent data in json (set format=json)

curl https://algoexplorerapi.io/v2/blocks/18174030\?format\=json -s > json-18174030

failing command

msgpack2json -i msgpack-18174030
msgpack2json: bin unencodable in JSON. Try debug viewing mode (-d)
mpack breakpoint hit at /home/nick/code/msgpack-tools/contrib/mpack-df17e83f0fa8571b9cd0d8ccf38144fa90e244d1/src/mpack/mpack-common.c:322
unclosed mpack_type_map
[1]    77951 illegal hardware instruction (core dumped)  msgpack2json -i msgpack-18174030

system

Linux 5.11.0-43-generic #47~20.04.2-Ubuntu SMP Mon Dec 13 11:06:56 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux

strace output

execve("/usr/bin/msgpack2json", ["msgpack2json", "-i", "msgpack-18174030"], 0x7ffdcea2f1f0 /* 37 vars */) = 0
brk(NULL)                               = 0x2016000
arch_prctl(0x3001 /* ARCH_??? */, 0x7ffd4310c180) = -1 EINVAL (Invalid argument)
access("/etc/ld.so.preload", R_OK)      = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=58760, ...}) = 0
mmap(NULL, 58760, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7f856b564000
close(3)                                = 0
openat(AT_FDCWD, "/lib/x86_64-linux-gnu/libstdc++.so.6", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\3\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0`\341\t\0\0\0\0\0"..., 832) = 832
fstat(3, {st_mode=S_IFREG|0644, st_size=1956992, ...}) = 0
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f856b562000
mmap(NULL, 1972224, PROT_READ, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f856b380000
mprotect(0x7f856b416000, 1290240, PROT_NONE) = 0
mmap(0x7f856b416000, 987136, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x96000) = 0x7f856b416000
mmap(0x7f856b507000, 299008, PROT_READ, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x187000) = 0x7f856b507000
mmap(0x7f856b551000, 57344, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x1d0000) = 0x7f856b551000
mmap(0x7f856b55f000, 10240, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7f856b55f000
close(3)                                = 0
openat(AT_FDCWD, "/lib/x86_64-linux-gnu/libm.so.6", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\3\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\300\363\0\0\0\0\0\0"..., 832) = 832
fstat(3, {st_mode=S_IFREG|0644, st_size=1369352, ...}) = 0
mmap(NULL, 1368336, PROT_READ, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f856b231000
mmap(0x7f856b240000, 684032, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0xf000) = 0x7f856b240000
mmap(0x7f856b2e7000, 618496, PROT_READ, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0xb6000) = 0x7f856b2e7000
mmap(0x7f856b37e000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x14c000) = 0x7f856b37e000
close(3)                                = 0
openat(AT_FDCWD, "/lib/x86_64-linux-gnu/libgcc_s.so.1", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\3405\0\0\0\0\0\0"..., 832) = 832
fstat(3, {st_mode=S_IFREG|0644, st_size=104984, ...}) = 0
mmap(NULL, 107592, PROT_READ, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f856b216000
mmap(0x7f856b219000, 73728, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x3000) = 0x7f856b219000
mmap(0x7f856b22b000, 16384, PROT_READ, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x15000) = 0x7f856b22b000
mmap(0x7f856b22f000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x18000) = 0x7f856b22f000
close(3)                                = 0
openat(AT_FDCWD, "/lib/x86_64-linux-gnu/libc.so.6", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\3\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\360q\2\0\0\0\0\0"..., 832) = 832
pread64(3, "\6\0\0\0\4\0\0\0@\0\0\0\0\0\0\0@\0\0\0\0\0\0\0@\0\0\0\0\0\0\0"..., 784, 64) = 784
pread64(3, "\4\0\0\0\20\0\0\0\5\0\0\0GNU\0\2\0\0\300\4\0\0\0\3\0\0\0\0\0\0\0", 32, 848) = 32
pread64(3, "\4\0\0\0\24\0\0\0\3\0\0\0GNU\0\t\233\222%\274\260\320\31\331\326\10\204\276X>\263"..., 68, 880) = 68
fstat(3, {st_mode=S_IFREG|0755, st_size=2029224, ...}) = 0
pread64(3, "\6\0\0\0\4\0\0\0@\0\0\0\0\0\0\0@\0\0\0\0\0\0\0@\0\0\0\0\0\0\0"..., 784, 64) = 784
pread64(3, "\4\0\0\0\20\0\0\0\5\0\0\0GNU\0\2\0\0\300\4\0\0\0\3\0\0\0\0\0\0\0", 32, 848) = 32
pread64(3, "\4\0\0\0\24\0\0\0\3\0\0\0GNU\0\t\233\222%\274\260\320\31\331\326\10\204\276X>\263"..., 68, 880) = 68
mmap(NULL, 2036952, PROT_READ, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f856b024000
mprotect(0x7f856b049000, 1847296, PROT_NONE) = 0
mmap(0x7f856b049000, 1540096, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x25000) = 0x7f856b049000
mmap(0x7f856b1c1000, 303104, PROT_READ, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x19d000) = 0x7f856b1c1000
mmap(0x7f856b20c000, 24576, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x1e7000) = 0x7f856b20c000
mmap(0x7f856b212000, 13528, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7f856b212000
close(3)                                = 0
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f856b022000
arch_prctl(ARCH_SET_FS, 0x7f856b022f40) = 0
mprotect(0x7f856b20c000, 12288, PROT_READ) = 0
mprotect(0x7f856b22f000, 4096, PROT_READ) = 0
mprotect(0x7f856b37e000, 4096, PROT_READ) = 0
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f856b020000
mprotect(0x7f856b551000, 45056, PROT_READ) = 0
mprotect(0x7f856b5a0000, 4096, PROT_READ) = 0
munmap(0x7f856b564000, 58760)           = 0
brk(NULL)                               = 0x2016000
brk(0x2037000)                          = 0x2037000
openat(AT_FDCWD, "msgpack-18174030", O_RDONLY) = 3
brk(0x205a000)                          = 0x205a000
fstat(3, {st_mode=S_IFREG|0664, st_size=119579, ...}) = 0
read(3, "\202\245block\336\0\20\244earn\316\0\3J\252\244fees\304 \307\374\315\262X"..., 4096) = 4096
write(2, "msgpack2json: bin unencodable in"..., 67) = 67
write(2, "mpack breakpoint hit at /home/ni"..., 162) = 162
--- SIGILL {si_signo=SIGILL, si_code=ILL_ILLOPN, si_addr=0x41bb25} ---
+++ killed by SIGILL (core dumped) +++