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


##########
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:
   Of the two escape sequences for code-points `0x10000` to `0x110000`, the 
first one must be between `0xd800` and `0xdbff` and the second one must be 
between `0xdc00` and `0xdfff`. And these rages cannot be used standalone or in 
the reverse order. Fixed it so that the first sequence has value between 
`0xd800`  (inclusive) and `0xdc00` (exclusive)



-- 
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