Repository navigation
fix segfault when length fields contain a big 32-bit number - #36
Conversation
When interpreting MessagePack 32-bit length fields, we incorrectly cast to int; this causes a field length of "\xff\xff\xff\xff" to be interpreted as -1, which is then casted to size_t as 18446744073709551615 (= max_uint64 - 1). The fix makes sure that all the size arithmetic is done as size_t; and prevents adding anything to a given size_t in order not to overflow (even on 32-bit builds).
|
Looks good to me. Better size checks and you made the consume/push flow easier to read too. All tests pass at https://travis-ci.org/mattsta/lua-cmsgpack/builds/43883884 |
fix segfault when length fields contain a big 32-bit number
|
Thanks! Merged. |
|
Thanks for the quick response. @mattsta - does Travis CI builds and tests both 64 and 32-bit builds? It's not clear from the |
It doesn't right now. We can easily build 32-bit cmsgpack lua modules, but with the TravisCI setup, it's difficult to build a matching 32-bit lua interpreter to load it for testing. My current failed attempt at getting a 32-bit test working is at mattsta@d18b60c but none of those settings make their way down into actually compiling the Lua interpreters themselves. If you can get it working, let me know. :) |
|
As a side effect of being part of Redis however the lib is tested in a 32 and 64 bit version, and valgrinded every night here: http://ci.redis.io/ |
When interpreting MessagePack 32-bit length fields, we incorrectly cast
to int; this causes a field length of "\xff\xff\xff\xff" to be
interpreted as -1, which is then casted to size_t as
18446744073709551615 (= max_uint64 - 1).
The fix makes sure that all the size arithmetic is done as size_t; and
prevents adding anything to a given size_t in order not to overflow
(even on 32-bit builds).
The customized problematic inputs appear in
test.lua.Note: this bug was found with the great automatic help of american fuzzy lop 0.89b.