KalleOlaviNiemitalo commented on code in PR #2831:
URL: https://github.com/apache/avro/pull/2831#discussion_r1547514412


##########
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:
   Yes this correctly rejects unpaired surrogates between 0xD800 and 0xDFFF.  
The problem is that `n >= 0xd800` also matches e.g. 0xE000 which is not a 
surrogate code unit.



-- 
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: issues-unsubscr...@avro.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to