Public bug reported:

According to the json specs, slashes can be encoded by using the escaped
sequence \/ - but PyString_DecodeEscape doesn't handle that particular
escape sequence, so valid json is decoded incorrectly.

Just try:

>>> import cjson, json
>>> cjson.decode(r'{"a":"image\/jpeg"}')
{'a': 'image\\/jpeg'}
>>> json.loads(r'{"a":"image\/jpeg"}')
{u'a': u'image/jpeg'}
>>> 

The attached patch solves the issue efficiently for strings shorter than
16K (a safety thing, we don't want huge arrays in the stack, and our own
use of cjson rarely ever handles strings longer than that). It won't die
on strings larger than 16K (simply not decode the slashes), so I believe
it's safe enough.

It would be simple enough to provide a path for the case of strings
longer than 16K by using malloc instead of alloca in those particular
cases. The trick would lie in making sure there was no memory leak in
that case.

** Affects: python-cjson (Ubuntu)
     Importance: Undecided
         Status: New

** Patch added: "Manually decode \/ prior to building a string with 
PyString_X()"
   
https://bugs.launchpad.net/bugs/1487243/+attachment/4449916/+files/python-cjson-1.1.0-slashdecode.patch

-- 
You received this bug notification because you are a member of Ubuntu
Bugs, which is subscribed to Ubuntu.
https://bugs.launchpad.net/bugs/1487243

Title:
  decode doesn't properly handle escaped slashes ("\/")

To manage notifications about this bug go to:
https://bugs.launchpad.net/ubuntu/+source/python-cjson/+bug/1487243/+subscriptions

-- 
ubuntu-bugs mailing list
[email protected]
https://lists.ubuntu.com/mailman/listinfo/ubuntu-bugs

Reply via email to