rtsisyk / msgpuck Goto Github PK
View Code? Open in Web Editor NEWA simple and efficient MsgPack binary serialization library in a self-contained header file
License: BSD 2-Clause "Simplified" License
A simple and efficient MsgPack binary serialization library in a self-contained header file
License: BSD 2-Clause "Simplified" License
hello, all
I have been using this libray, but failed at encode_int. when I looked into the code, I found:
"
MP_IMPL char *
mp_encode_int(char *data, int64_t num)
{
assert(num < 0);
if (num >= -0x20) {
"
what's the reason to force "num <0"
GLIBC allow to register a custom printf() modificator: https://www.gnu.org/software/libc/manual/html_node/Registering-New-Conversions.html#Registering-New-Conversions
cmake -S Common/Import/msgpuck -B Common/Import/msgpuck/build
1141-- The CXX compiler identification is GNU 10.2.1
1142-- Detecting C compiler ABI info
1143-- The C compiler identification is GNU 10.2.1
1144-- Detecting C compiler ABI info
1145-- Detecting C compiler ABI info - done
1146-- Detecting C compiler ABI info - done
1147-- Check for working C compiler: /usr/bin/aarch64-linux-gnu-gcc - skipped
1148-- Detecting C compile features
1149-- Detecting C compile features - done
1150-- Detecting CXX compiler ABI info
1151-- Check for working C compiler: /usr/bin/aarch64-linux-gnu-gcc - skipped
1152-- Detecting C compile features
1153-- Detecting C compile features - done
1154-- Performing Test CC_HAS_MNO_UNALIGNED_ACCESS
1155-- Performing Test CC_HAS_MNO_UNALIGNED_ACCESS - Failed
Adapt stream encoder like struct mpstream
in Tarantool:
https://github.com/tarantool/tarantool/blob/8f59f439672f0b470d20a176da9876ad120d4244/src/lua/msgpack.h#L69
int k
counter inside mp_check()/mp_next() is not enough to store uint32_t
size.
See an example in tarantool/nginx_upstream_module#79
TALOS-2016-0254
CVE-2016-9036
Add mp_fprint(FILE *, char *data)
to use for debugging purpose.
ok 3 - subtests
1..27
# *** test_floats ***
# float (float) 1.0
ok 1 - mp_check_float((float) 1.0) == 0
Program received signal SIGBUS, Bus error.
(gdb) bt
#0 0x0003c974 in mp_decode_float (data=0xbefff5bc) at /home/roman/work/tarantool/master/src/lib/msgpuck/msgpuck.h:1386
#1 0x0001b568 in test_floats () at /home/roman/work/tarantool/master/src/lib/msgpuck/test/msgpuck.c:163
#2 0x0003ac8c in main () at /home/roman/work/tarantool/master/src/lib/msgpuck/test/msgpuck.c:488
[ 84%] Building C object test/unit/CMakeFiles/msgpack.test.dir/__/__/src/lib/msgpuck/test/msgpuck.c.o
In file included from /home/mons/src/tarantool/src/lib/msgpuck/test/msgpuck.c:39:0:
/home/mons/src/tarantool/src/lib/msgpuck/test/msgpuck.c: In function ‘test_format’:
/home/mons/src/tarantool/src/lib/msgpuck/test/msgpuck.c:702:12: error: comparison between signed and unsigned integer expressions [-Werror=sign-compare]
ok((c - p == data1_len) &&
^
/home/mons/src/tarantool/src/lib/msgpuck/test/test.h:83:17: note: in definition of macro ‘ok’
int res = __ok(condition, fmt, ##args); \
^
/home/mons/src/tarantool/src/lib/msgpuck/test/msgpuck.c: At top level:
cc1: error: unrecognized command line option "-Wno-tautological-compare" [-Werror]
cc1: error: unrecognized command line option "-Wno-format-truncation" [-Werror]
cc1: all warnings being treated as errors
test/unit/CMakeFiles/msgpack.test.dir/build.make:62: recipe for target 'test/unit/CMakeFiles/msgpack.test.dir/__/__/src/lib/msgpuck/test/msgpuck.c.o' failed
make[2]: *** [test/unit/CMakeFiles/msgpack.test.dir/__/__/src/lib/msgpuck/test/msgpuck.c.o] Error 1
CMakeFiles/Makefile2:3133: recipe for target 'test/unit/CMakeFiles/msgpack.test.dir/all' failed
make[1]: *** [test/unit/CMakeFiles/msgpack.test.dir/all] Error 2
Makefile:149: recipe for target 'all' failed
make: *** [all] Error 2
gcc version 4.9.3 (Funtoo 4.9.3-r1)
msgpuck 2.0 with backported 40e24cc.
Test mp_read_double(mp_encode_double(-5.555)) check result
fails on x86, but not x86_64.
ok 61 - mp_read_double(mp_encode_uint(123)) check success
ok 62 - mp_read_double(mp_encode_uint(123)) check pos advanced
ok 63 - mp_read_double(mp_encode_uint(123)) check result
ok 64 - mp_read_double(mp_encode_uint(12345)) check success
ok 65 - mp_read_double(mp_encode_uint(12345)) check pos advanced
ok 66 - mp_read_double(mp_encode_uint(12345)) check result
ok 67 - mp_read_double(mp_encode_uint(123456789)) check success
ok 68 - mp_read_double(mp_encode_uint(123456789)) check pos advanced
ok 69 - mp_read_double(mp_encode_uint(123456789)) check result
ok 70 - mp_read_double(mp_encode_uint(1234567890000ULL)) check success
ok 71 - mp_read_double(mp_encode_uint(1234567890000ULL)) check pos advanced
ok 72 - mp_read_double(mp_encode_uint(1234567890000ULL)) check result
ok 73 - mp_read_double(mp_encode_uint(123456789123456789ULL)) check fail
ok 74 - mp_read_double(mp_encode_uint(123456789123456789ULL)) check pos unchanged
ok 75 - mp_read_double(mp_encode_int(-123)) check success
ok 76 - mp_read_double(mp_encode_int(-123)) check pos advanced
ok 77 - mp_read_double(mp_encode_int(-123)) check result
ok 78 - mp_read_double(mp_encode_int(-12345)) check success
ok 79 - mp_read_double(mp_encode_int(-12345)) check pos advanced
ok 80 - mp_read_double(mp_encode_int(-12345)) # Failed test 'mp_read_double(mp_encode_double(-5.555)) check result'
# in /home/buildozer/aports/testing/msgpuck/src/msgpuck-2.0/test/msgpuck.c at line 1051
check result
ok 81 - mp_read_double(mp_encode_int(-123456789)) check success
ok 82 - mp_read_double(mp_encode_int(-123456789)) check pos advanced
ok 83 - mp_read_double(mp_encode_int(-123456789)) check result
ok 84 - mp_read_double(mp_encode_int(-1234567890000LL)) check success
ok 85 - mp_read_double(mp_encode_int(-1234567890000LL)) check pos advanced
ok 86 - mp_read_double(mp_encode_int(-1234567890000LL)) check result
ok 87 - mp_read_double(mp_encode_int(-123456789123456789LL)) check fail
ok 88 - mp_read_double(mp_encode_int(-123456789123456789LL)) check pos unchanged
ok 89 - mp_read_double(mp_encode_float(6.565e6)) check success
ok 90 - mp_read_double(mp_encode_float(6.565e6)) check pos advanced
ok 91 - mp_read_double(mp_encode_float(6.565e6)) check result
ok 92 - mp_read_double(mp_encode_double(-5.555)) check success
ok 93 - mp_read_double(mp_encode_double(-5.555)) check pos advanced
-> not ok 94 - mp_read_double(mp_encode_double(-5.555)) check result <-
# Looks like you failed 1 test of 96 run.
# Failed test 'subtests'
# in /home/buildozer/aports/testing/msgpuck/src/msgpuck-2.0/test/test.c at line 85
# Looks like you failed 1 test of 20 run.
ok 95 - mp_read_double(mp_encode_strl(100)) check fail
ok 96 - mp_read_double(mp_encode_strl(100)) check pos unchanged
# *** test_numbers: done ***
not ok 19 - subtests
Please add the ext specification: encode/decode https://github.com/msgpack/msgpack/blob/master/spec.md#formats-ext
The some code of encode/decode is https://github.com/akalend/hhvm-msgpack/blob/hhvm-v-3.12/msgpuck.h#L1515-L1540 and
https://github.com/akalend/hhvm-msgpack/blob/hhvm-v-3.12/msgpuck.h#L1627-L1659
but it is not full realisation of specification: absent small objects 1,2,4 and 16 bytes.
So, must be the function mp_sizeof_ext(), mp_check_ext()
Thanks
The list of problems found by PVS Studio by Viva64 in 1.1-6-g466b6a6:
Proposal 1:
/*
* Decodes an integer or a floting point value as double.
*
* \param data the pointer to a buffer
* \param deflt a value to return on error
* \retval number on success
* \retval deflt on overflow
* \retval deflt if underlying mp type is not MP_INT, MP_UINT,
* MP_FLOAT or MP_DOUBLE.
*/
static inline double
mp_read_double(const char **data, double deflt);
/*
* Decodes an integer value as int64_t.
*
* \param data the pointer to a buffer
* \param deflt a value to return on error
* \retval number on success
* \retval deflt on overflow
* \retval deflt if underlying mp type is not MP_INT, MP_UINT.
*/
static inline double
mp_read_int64(const char **data, int64_t deflt);
Proposal 2:
/*
* Decodes an integer or a floting point value as double.
*
* \param[out] ret return value
* \retval 0 on success
* \retval -1 on overflow, *ret is set to zero
* \retval -1 if underlying mp type is not MP_INT, MP_UINT,
* MP_FLOAT or MP_DOUBLE, *ret is set to zero.
*/
static inline int
mp_read_double(const char **data, double *ret);
/*
* Decodes an integer value as int64_t.
*
* \param[out] ret return value
* \retval 0 on success
* \retval -1 on overflow, *ret is set to zero
* \retval -1 if underlying mp type is not MP_INT, MP_UINT, *ret is set to zero
*/
static inline int
mp_read_int64(const char **data, int64_t *ret);
mp_decode_double() is already used, mp_decode_int64() is reserved for the future.
Any other ideas?
Hello,
First, thanks for this great "inline" msgpuck.
I was facing a typeof mutation problem which seems normal in the code but a bit disturbing when i worked on it.
You can not just do a mp_encode_int / mp_decode_int.
In this case, you must call the mp_typeof before the decode because the int could be changed to a uint if (0<=i<=127).
mp_encode_int( s, 1 );
assert(mp_typeof(*s) == MP_INT);
Perhaps it should be specified in the documentation.
Regards,
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.