Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion lightning/src/util/ser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1688,7 +1688,14 @@ impl Readable for Duration {
fn read<R: Read>(r: &mut R) -> Result<Self, DecodeError> {
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))
}
}
}

Expand Down
Loading