@@ -850,14 +850,15 @@ void CBORTokenizer::ReadNextToken(bool enter_envelope) {
850
850
return;
851
851
case MajorType::NEGATIVE: { // INT32.
852
852
// 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()) {
861
862
SetError(Error::CBOR_INVALID_INT32);
862
863
return;
863
864
}
@@ -1864,7 +1865,7 @@ class JsonParser {
1864
1865
// If the |Char| we're dealing with is really a byte, then
1865
1866
// we have utf8 here, and we need to check for multibyte characters
1866
1867
// 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) {
1868
1869
// Inspect the leading byte to figure out how long the utf8
1869
1870
// byte sequence is; while doing this initialize |codepoint|
1870
1871
// with the first few bits.
@@ -1903,7 +1904,7 @@ class JsonParser {
1903
1904
// Disallow overlong encodings for ascii characters, as these
1904
1905
// would include " and other characters significant to JSON
1905
1906
// string termination / control.
1906
- if (codepoint < 0x7f)
1907
+ if (codepoint <= 0x7f)
1907
1908
return false;
1908
1909
// Invalid in UTF8, and can't be represented in UTF16 anyway.
1909
1910
if (codepoint > 0x10ffff)
0 commit comments