diff --git a/lightning/src/util/ser.rs b/lightning/src/util/ser.rs index e88e1eb3732..d78b3e921cc 100644 --- a/lightning/src/util/ser.rs +++ b/lightning/src/util/ser.rs @@ -1688,7 +1688,14 @@ impl Readable for Duration { fn read(r: &mut R) -> Result { let secs = Readable::read(r)?; let nanos = Readable::read(r)?; - Ok(Duration::new(secs, nanos)) + // Duration::new panics if the nanosecond part in excess of a second, added to the second + // part, overflows. To ensure this won't happen, we simply reject any case where there are + // nanoseconds in excess of a second, which is invalid anyway. + if nanos >= 1_000_000_000 { + Err(DecodeError::InvalidValue) + } else { + Ok(Duration::new(secs, nanos)) + } } }