Skip to content

Commit c1a204d

Browse files
committed
fix(consistent-bincode): overflow when parsing malformed data
1 parent 9623a3c commit c1a204d

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

float-pigment-consistent-bincode/src/de/mod.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,12 @@ impl<'de, R: BincodeRead<'de>, O: Options> Deserializer<R, O> {
8383
let seg_size = O::IntEncoding::deserialize_u32(self)? as usize;
8484
let ssl = SegmentSizeLimit {
8585
diff: match self.segment_size_limits.last() {
86-
Some(_) => Some(self.reader.barrier() - seg_size),
86+
Some(_) => Some(
87+
self.reader
88+
.barrier()
89+
.checked_sub(seg_size)
90+
.ok_or(ErrorKind::InvalidData)?,
91+
),
8792
None => None,
8893
},
8994
};

float-pigment-consistent-bincode/src/error.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ pub enum ErrorKind {
3737
Custom(String),
3838
/// No enough segment data to read.
3939
SegmentEnded,
40+
/// Invalid data
41+
InvalidData,
4042
}
4143

4244
impl serde::de::StdError for ErrorKind {
@@ -52,6 +54,7 @@ impl serde::de::StdError for ErrorKind {
5254
ErrorKind::SizeLimit => None,
5355
ErrorKind::Custom(_) => None,
5456
ErrorKind::SegmentEnded => None,
57+
ErrorKind::InvalidData => None,
5558
}
5659
}
5760
}
@@ -85,6 +88,7 @@ impl fmt::Display for ErrorKind {
8588
),
8689
ErrorKind::Custom(ref s) => s.fmt(fmt),
8790
ErrorKind::SegmentEnded => write!(fmt, "the segment does not contain enough data"),
91+
ErrorKind::InvalidData => write!(fmt, "the data is invalid"),
8892
}
8993
}
9094
}

0 commit comments

Comments
 (0)