From 75ee6bfcf40b531024fad9a5ebb0908859769816 Mon Sep 17 00:00:00 2001 From: Mark Pulford Date: Sun, 8 May 2011 20:57:05 +0930 Subject: Generate error when attempting to decode UTF-16/32 --- lua_cjson.c | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'lua_cjson.c') diff --git a/lua_cjson.c b/lua_cjson.c index 52b259d..179c830 100644 --- a/lua_cjson.c +++ b/lua_cjson.c @@ -1167,6 +1167,14 @@ static int json_decode(lua_State *l) json = luaL_checklstring(l, 1, &len); + /* Detect Unicode other than UTF-8 (see RFC 4627, Sec 3) + * + * CJSON can support any simple data type, hence only the first + * character is guaranteed to be ASCII (at worst: "). This is + * still enough to detect whether the wrong encoding is in use. */ + if (len >= 2 && (!json[0] || !json[1])) + luaL_error(l, "JSON parser does not support UTF-16 or UTF-32"); + lua_json_decode(l, json, len); return 1; -- cgit v1.2.3-55-g6feb