Accommodate arith-overflow in serialize::json numeric parsing.

This commit is contained in:
Felix S. Klock II 2015-02-19 19:21:53 +01:00
parent c8db89aa82
commit 7c8edabac8

View File

@ -1569,8 +1569,8 @@ impl<T: Iterator<Item=char>> Parser<T> {
while !self.eof() {
match self.ch_or_null() {
c @ '0' ... '9' => {
accum *= 10;
accum += (c as u64) - ('0' as u64);
accum = accum.wrapping_mul(10);
accum = accum.wrapping_add((c as u64) - ('0' as u64));
// Detect overflow by comparing to the last value.
if accum <= last_accum { return self.error(InvalidNumber); }