Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UINT32 IS BORKED #101

Closed
invisig0th opened this issue May 23, 2014 · 3 comments
Closed

UINT32 IS BORKED #101

invisig0th opened this issue May 23, 2014 · 3 comments

Comments

@invisig0th
Copy link

In 0.4.2 ( and some prior versions ) the C implementation for uint32 decoding is broken:

In unpack_callback_uint32 ( from unpack.h ) the line:
p = PyInt_FromLong((long)d);

causes unsigned 32 bit integers to unpack as negative values in python:
ie. the hex "ce f0 00 00 00" unpacks to -268435456 rather than 4026531840

this can lead to catastrophic data corruption at the application layer when dealing with integers between 2 and 4 billion.

I would recommend changing to:
p = PyLong_FromUnsignedLong((unsigned long)d);

with a possible check against INT32_MAX ( not UINT32_MAX ) to create the slightly smaller/faster PyInt_FromLong() case, but only when the value will not trigger negative interpretation as a PyInt.

@methane
Copy link
Member

methane commented May 25, 2014

Thank you. I'll fix it soon.

This may be a problem only on 32bit or LLP64 (Windows 64bit).
I want a CI for such environment...

@methane
Copy link
Member

methane commented May 25, 2014

Fixed via 7f623c0

@ThomasWaldmann
Copy link
Contributor

Also affects 0.3.0 (this is the version in ubuntu 14.04 lts):

https://github.com/msgpack/msgpack-python/blob/0.3.0/msgpack/unpack.h#L75

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

No branches or pull requests

3 participants