diff options
author | Loppin Vincent <vincent.loppin@gmail.com> | 2018-07-25 02:13:30 +0200 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2018-07-24 17:13:30 -0700 |
commit | 89ac9f8bb7e9bfaa57fd2c9bf0c6e950bd06e123 (patch) | |
tree | 38654e147beaf671321ed2081da7ca6c0ef042bf /src | |
parent | f7d9536ad653a9e6cc059c1539c2807e754be264 (diff) | |
download | binaryen-89ac9f8bb7e9bfaa57fd2c9bf0c6e950bd06e123.tar.gz binaryen-89ac9f8bb7e9bfaa57fd2c9bf0c6e950bd06e123.tar.bz2 binaryen-89ac9f8bb7e9bfaa57fd2c9bf0c6e950bd06e123.zip |
Notice parse errors on number parsing in the text format (#1608)
* - Throw ParseException when istringstream failed to read a number.
- Modify now invalid tests.
* Add invalid_number.wast test
Diffstat (limited to 'src')
-rw-r--r-- | src/parsing.h | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/src/parsing.h b/src/parsing.h index 06797cf54..c6a3b8a83 100644 --- a/src/parsing.h +++ b/src/parsing.h @@ -126,6 +126,7 @@ inline Expression* parseConst(cashew::IString s, Type type, MixedArena& allocato if (modifier) { std::istringstream istr(modifier); istr >> std::hex >> pattern; + if (istr.fail()) throw ParseException("invalid f32 format"); pattern |= 0x7f800000U; } else { pattern = 0x7fc00000U; @@ -140,6 +141,7 @@ inline Expression* parseConst(cashew::IString s, Type type, MixedArena& allocato if (modifier) { std::istringstream istr(modifier); istr >> std::hex >> pattern; + if (istr.fail()) throw ParseException("invalid f64 format"); pattern |= 0x7ff0000000000000ULL; } else { pattern = 0x7ff8000000000000UL; @@ -172,11 +174,13 @@ inline Expression* parseConst(cashew::IString s, Type type, MixedArena& allocato std::istringstream istr(str); uint32_t temp; istr >> std::hex >> temp; + if (istr.fail()) throw ParseException("invalid i32 format"); ret->value = Literal(negative ? -temp : temp); } else { std::istringstream istr(str[0] == '-' ? str + 1 : str); uint32_t temp; istr >> temp; + if (istr.fail()) throw ParseException("invalid i32 format"); ret->value = Literal(str[0] == '-' ? -temp : temp); } break; @@ -188,11 +192,13 @@ inline Expression* parseConst(cashew::IString s, Type type, MixedArena& allocato std::istringstream istr(str); uint64_t temp; istr >> std::hex >> temp; + if (istr.fail()) throw ParseException("invalid i64 format"); ret->value = Literal(negative ? -temp : temp); } else { std::istringstream istr(str[0] == '-' ? str + 1 : str); uint64_t temp; istr >> temp; + if (istr.fail()) throw ParseException("invalid i64 format"); ret->value = Literal(str[0] == '-' ? -temp : temp); } break; |