KalleOlaviNiemitalo commented on code in PR #2831:
URL: https://github.com/apache/avro/pull/2831#discussion_r1554509918
##########
lang/c++/impl/json/JsonIO.cc:
##########
@@ -350,30 +372,42 @@ string JsonParser::decodeString(const string &s, bool
binary) {
continue;
case 'u':
case 'U': {
- uint32_t n = 0;
- char e[4];
- for (char &i : e) {
- n *= 16;
- char c = readNextByte(it, end);
- 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;
- }
- }
+ uint32_t n = unicodeParse();
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 && n < 0xdc00) {
+ ch = readNextByte();
+ if (ch != '\\') {
+ throw Exception(boost::format(
+ "Invalid unicode sequence:
%1%")
+ % string(startSeq, it));
+ }
+ ch = readNextByte();
+ if (ch != 'u' && ch != 'U') {
+ throw Exception(boost::format(
+ "Invalid unicode sequence:
%1%")
+ % string(startSeq, it));
+ }
+ uint32_t m = unicodeParse();
+ if (m < 0xdc00 || m > 0xdfff) {
+ throw Exception(boost::format(
+ "Invalid unicode sequence:
%1%")
+ % string(startSeq, it));
+ }
+ n = 0x10000 + (((n - 0xd800) << 10) | (m - 0xdc00));
+ } else if (n >= 0xdc00 && n < 0xdfff) {
Review Comment:
This still doesn’t look right; it treats 0xdfff differently from 0xdffe even
though both of these are surrogate code units. I think the second comparison
should instead be `n <= 0xdfff` or `n < 0xe000`.
--
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]