thiru-mg commented on code in PR #2831:
URL: https://github.com/apache/avro/pull/2831#discussion_r1547508566


##########
lang/c++/impl/json/JsonIO.cc:
##########
@@ -344,29 +370,49 @@ string JsonParser::decodeString(const string &s, bool 
binary) {
                 case 'u':
                 case 'U': {
                     uint32_t n = 0;
-                    char e[4];
-                    for (char &i : e) {
-                        n *= 16;
-                        char c = *++it;
-                        i = c;
-                        if (isdigit(c)) {
-                            n += c - '0';
-                        } else if (c >= 'a' && c <= 'f') {
-                            n += c - 'a' + 10;
-                        } else if (c >= 'A' && c <= 'F') {
-                            n += c - 'A' + 10;
-                        }
-                    }
+                    it = unicodeParse(it, s.end(), n);
                     if (binary) {
                         if (n > 0xff) {
                             throw Exception(boost::format(
                                                 "Invalid byte for binary: 
%1%%2%")
-                                            % ch % string(e, 4));
+                                            % ch % string(startSeq, ++it));
                         } else {
                             result.push_back(n);
                             continue;
                         }
                     }
+                    if (n >= 0xd800) {
+                        ++it;
+                        if (n > 0xdbff || it == s.end()) {
+                            throw Exception(boost::format(
+                                                "Invalid unicode sequence: 
%1%")
+                                            % string(startSeq, it));

Review Comment:
   Unicode code points between `0x10000` and `0x110000` are encoded as two 
`\uxxxx\uyyyy` where `xxxx` is in the range `0xd800` to `0xdbff` and `yyyy` is 
in the range `0xdc00` to `0xdffff`. The range from `0xd800` to `0xdf00` are 
reserved only for this encoding and no true Unicode chacters are defined there. 
Please see section 2 of https://www.ietf.org/rfc/rfc2781.txt: `Note: Values 
between 0xD800 and 0xDFFF are specifically reserved for
      use with UTF-16, and don't have any characters assigned to them.`



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to