There was an error while loading. Please reload this page.
2 parents 6941b0a + 7b9bde1 commit c218818Copy full SHA for c218818
lightning/src/util/ser.rs
@@ -1688,7 +1688,14 @@ impl Readable for Duration {
1688
fn read<R: Read>(r: &mut R) -> Result<Self, DecodeError> {
1689
let secs = Readable::read(r)?;
1690
let nanos = Readable::read(r)?;
1691
-Ok(Duration::new(secs, nanos))
+// Duration::new panics if the nanosecond part in excess of a second, added to the second
1692
+// part, overflows. To ensure this won't happen, we simply reject any case where there are
1693
+// nanoseconds in excess of a second, which is invalid anyway.
1694
+if nanos >= 1_000_000_000 {
1695
+Err(DecodeError::InvalidValue)
1696
+} else {
1697
+Ok(Duration::new(secs, nanos))
1698
+}
1699
}
1700
1701
0 commit comments