#14 json_encode64 bug

closed
nobody
None
5
2011-07-06
2011-06-18
Anonymous
No

When JSON_EXPOSE_BASE64 is defined and JSON_MEMORY_MANAGE is not defined, json_encode64 does not work correctly. It doesn't allocated enough memory for the base64 encoded string, and the string returned is not NULL terminated either.

Here is the fix (libjson.cpp):
json_char * json_encode64(json_const void * binary, json_index_t bytes){
const json_string result(JSONBase64::json_encode64((const unsigned char *)binary, (size_t)bytes));
#ifdef JSON_MEMORY_MANAGE
return StringHandler.insert(memcpy(json_malloc<json_char>(result.length()), result.c_str(), result.length()));
#else
// ************** START FIX **************
json_char* p = json_malloc<json_char>(result.length() + 1);
memcpy(p, result.c_str(), result.length());
p[result.length()] = 0;
return p;
// ************** END FIX **************
#endif
}

Discussion

  • Jonathan Wallace

    Thank you, I am adding this as a bug fix now

     
  • Jonathan Wallace

    • status: open --> closed
     
  • Jonathan Wallace

    Code frozen with this bug fixed in it. Once the unit test suite runs successfully, the new version will be pushed out

     

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.





No, thanks