diff --git a/pymongo/_cbsonmodule.c b/pymongo/_cbsonmodule.c index 9779c9b73..9d740af24 100644 --- a/pymongo/_cbsonmodule.c +++ b/pymongo/_cbsonmodule.c @@ -516,7 +516,7 @@ static PyObject* _elements_to_dict(PyObject* elements) { { int length; memcpy(&length, string + position, 4); - int subtype = (int)string[position + 4]; + int subtype = (unsigned char)string[position + 4]; PyObject* data; if (subtype == 2) { data = PyString_FromStringAndSize(string + position + 9, length - 4); diff --git a/test/test_bson.py b/test/test_bson.py index 18fb2781b..103bf6405 100644 --- a/test/test_bson.py +++ b/test/test_bson.py @@ -114,6 +114,7 @@ class TestBSON(unittest.TestCase): helper({"an object": {"test": u"something"}}) helper({"a binary": Binary("test", 100)}) helper({"a binary": Binary("test", 128)}) + helper({"a binary": Binary("test", 254)}) helper({"another binary": Binary("test")}) helper(SON([(u'test dst', datetime.datetime(1993, 4, 4, 2))]))