1
0
Fork 0
mirror of https://codeberg.org/demostf/parser.git synced 2026-06-03 10:14:06 +02:00

fix some more overflow panics

This commit is contained in:
Robin Appelman 2020-01-20 21:07:32 +01:00
commit 66d568a65f
3 changed files with 3 additions and 4 deletions

View file

@ -62,7 +62,6 @@ impl Parse for GameEventMessage {
}
}
None => {
dbg!(state.event_definitions.len());
return Err(ParseError::MalformedGameEvent(GameEventError::UnknownType(
event_type,
)));

View file

@ -235,11 +235,11 @@ impl PacketEntitiesMessage {
send_table: &SendTable,
props: &mut Vec<SendProp>,
) -> Result<()> {
let mut index = -1;
let mut index: i32 = -1;
while stream.read()? {
let diff: u32 = read_bit_var(stream)?;
index += (diff as i32) + 1;
index = index.saturating_add(diff as i32).saturating_add(1);
match send_table.flattened_props.get(index as usize) {
Some(definition) => {

View file

@ -483,7 +483,7 @@ impl SendPropValue {
.ok_or(MalformedSendPropDefinitionError::UnsizedFloat)?;
let raw: u32 = stream.read_int(bit_count as usize)?;
// is this -1 correct?, it is consistent with the js version but seems weird
let percentage = (raw as f32) / ((1 << bit_count) as f32 - 1.0);
let percentage = (raw as f32) / ((1i32.wrapping_shl(bit_count)) as f32 - 1.0);
Ok(low + ((high - low) * percentage))
}
}