Handle empty BigInt literals in the parser
Summary: OSS-Fuzz found that empty octal/hex/binary BigInt literals trigger an assert in our parser, since we don't correctly handle the case where there are no digits after the 0o/0x/0b. For example, `0bn` triggers this assert because after consuming the trailing "n", we assume that some digits were consumed, which isn't necessarily true. Reviewed By: tmikov Differential Revision: D37755199 fbshipit-source-id: 48805e0684ce4518a10e32ce17b02e22308444fa
This commit is contained in:
Родитель
4ea4cb25c5
Коммит
5a333f3d75
|
@ -1461,13 +1461,13 @@ end:
|
|||
|
||||
llvh::StringRef raw{rawStart, (size_t)(curCharPtr_ - rawStart)};
|
||||
if (ok && !real && (!legacyOctal || raw == "0n") && tmpStorage_ == "n") {
|
||||
assert(curCharPtr_ > start + 1 && "there should be numbers here");
|
||||
assert(curCharPtr_ > start && "Must consume at least the trailing n.");
|
||||
llvh::ArrayRef<char> digits{start, curCharPtr_ - 1};
|
||||
// use parseIntWithRadix to validate the bigint literal's digits. The
|
||||
// converted value does not matter, only whether or not the string was
|
||||
// parsed correctly.
|
||||
if (parseIntWithRadix</* AllowNumericSeparator */ true>(
|
||||
llvh::ArrayRef<char>{start, (size_t)(curCharPtr_ - start - 1)},
|
||||
radix)) {
|
||||
if (digits.size() &&
|
||||
parseIntWithRadix</* AllowNumericSeparator */ true>(digits, radix)) {
|
||||
// This is a BigInt.
|
||||
rawStorage_.clear();
|
||||
rawStorage_.append(raw);
|
||||
|
|
|
@ -17,3 +17,6 @@
|
|||
|
||||
0b2n
|
||||
// CHECK: invalid numeric literal
|
||||
|
||||
0bn
|
||||
// CHECK: invalid numeric literal
|
||||
|
|
Загрузка…
Ссылка в новой задаче