@@ -850,14 +850,15 @@ void CBORTokenizer::ReadNextToken(bool enter_envelope) {
850850 return;
851851 case MajorType::NEGATIVE: { // INT32.
852852 // INT32 is a signed int32 (int32 makes sense for the
853- // inspector_protocol, it's not a CBOR limitation); in CBOR,
854- // the negative values for INT32 are represented as NEGATIVE,
855- // that is, -1 INT32 is represented as 1 << 5 | 0 (major type 1,
856- // additional info value 0). So here, we compute the INT32 value
857- // and then check it against the INT32 min.
858- int64_t actual_value =
859- -static_cast<int64_t>(token_start_internal_value_) - 1;
860- if (!success || actual_value < std::numeric_limits<int32_t>::min()) {
853+ // inspector_protocol, it's not a CBOR limitation); in CBOR, the
854+ // negative values for INT32 are represented as NEGATIVE, that is, -1
855+ // INT32 is represented as 1 << 5 | 0 (major type 1, additional info
856+ // value 0). The minimal allowed INT32 value in our protocol is
857+ // std::numeric_limits<int32_t>::min(). We check for it by directly
858+ // checking the payload against the maximal allowed signed (!) int32
859+ // value.
860+ if (!success || token_start_internal_value_ >
861+ std::numeric_limits<int32_t>::max()) {
861862 SetError(Error::CBOR_INVALID_INT32);
862863 return;
863864 }
@@ -1864,7 +1865,7 @@ class JsonParser {
18641865 // If the |Char| we're dealing with is really a byte, then
18651866 // we have utf8 here, and we need to check for multibyte characters
18661867 // and transcode them to utf16 (either one or two utf16 chars).
1867- if (sizeof(Char) == sizeof(uint8_t) && c >= 0x7f) {
1868+ if (sizeof(Char) == sizeof(uint8_t) && c > 0x7f) {
18681869 // Inspect the leading byte to figure out how long the utf8
18691870 // byte sequence is; while doing this initialize |codepoint|
18701871 // with the first few bits.
@@ -1903,7 +1904,7 @@ class JsonParser {
19031904 // Disallow overlong encodings for ascii characters, as these
19041905 // would include " and other characters significant to JSON
19051906 // string termination / control.
1906- if (codepoint < 0x7f)
1907+ if (codepoint <= 0x7f)
19071908 return false;
19081909 // Invalid in UTF8, and can't be represented in UTF16 anyway.
19091910 if (codepoint > 0x10ffff)
0 commit comments