Skip to content

fix segfault when length fields contain a big 32-bit number - #36

Merged
antirez merged 1 commit into
antirez:masterfrom
dubek:fix-big-32bit-len-segfault
Dec 12, 2014
Merged

antirez merged 1 commit into
antirez:masterfrom
dubek:fix-big-32bit-len-segfault

Conversation

@dubek

@dubek dubek commented Dec 12, 2014

Copy link
Copy Markdown

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.

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).
@mattsta

mattsta commented Dec 12, 2014

Copy link
Copy Markdown
Contributor

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

antirez added a commit that referenced this pull request Dec 12, 2014
fix segfault when length fields contain a big 32-bit number
@antirez
antirez merged commit ee648f8 into antirez:master Dec 12, 2014
@antirez

antirez commented Dec 12, 2014

Copy link
Copy Markdown
Owner

Thanks! Merged.

@dubek

dubek commented Dec 15, 2014

Copy link
Copy Markdown
Author

Thanks for the quick response.

@mattsta - does Travis CI builds and tests both 64 and 32-bit builds? It's not clear from the .travis/setup_lua.sh file, but the README certainly has special build instructions for 32-bit.

@mattsta

mattsta commented Dec 18, 2014

Copy link
Copy Markdown
Contributor

does Travis CI builds and tests both 64 and 32-bit builds?

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. :)

@antirez

antirez commented Dec 18, 2014

Copy link
Copy Markdown
Owner

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/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants