Skip to content

Commit

Permalink
Move magic numbers to constants
Browse files Browse the repository at this point in the history
  • Loading branch information
Koenvh1 committed Jan 20, 2025
1 parent 23539f8 commit 32a55fe
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions src/rrdp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ use crate::xml::decode::{Content, Error as XmlError, Reader, Name};
};


//------------ Maximum XML sizes ---------------------------------------------

const MAX_FILE_SIZE: u128 = 100_000_000;
const MAX_HEADER_SIZE: u128 = 1_000_000;

//------------ NotificationFile ----------------------------------------------

/// The RRDP Update Notification File.
Expand Down Expand Up @@ -244,7 +249,7 @@ impl NotificationFile {
_ => Err(XmlError::Malformed)
}
})
}, 100_000_000)?;
}, MAX_HEADER_SIZE)?;

let mut snapshot = None;

Expand Down Expand Up @@ -318,7 +323,7 @@ impl NotificationFile {
}
_ => Err(XmlError::Malformed)
}
}, 100_000_000)? {
}, MAX_HEADER_SIZE)? {
content.take_end(&mut reader)?;
}

Expand Down Expand Up @@ -802,7 +807,7 @@ pub trait ProcessSnapshot {
Err(XmlError::Malformed)
}
})
}, 100_000_000).map_err(Into::into)?;
}, MAX_HEADER_SIZE).map_err(Into::into)?;

match (session_id, serial) {
(Some(session_id), Some(serial)) => {
Expand Down Expand Up @@ -831,7 +836,7 @@ pub trait ProcessSnapshot {
Err(ProcessError::malformed())
}
})
},100_000_000)?;
},MAX_FILE_SIZE)?;
let mut inner = match inner {
Some(inner) => inner,
None => break
Expand Down Expand Up @@ -1086,7 +1091,7 @@ pub trait ProcessDelta {

let mut session_id = None;
let mut serial = None;
let mut outer = reader.start(|element| {
let mut outer = reader.start_with_limit(|element| {
if element.name() != DELTA {
return Err(ProcessError::malformed())
}
Expand All @@ -1107,7 +1112,7 @@ pub trait ProcessDelta {
}
_ => Err(ProcessError::malformed())
})
})?;
}, MAX_HEADER_SIZE)?;

match (session_id, serial) {
(Some(session_id), Some(serial)) => {
Expand All @@ -1120,7 +1125,7 @@ pub trait ProcessDelta {
let mut action = None;
let mut uri = None;
let mut hash = None;
let inner = outer.take_opt_element(&mut reader, |element| {
let inner = outer.take_opt_element_with_limit(&mut reader, |element| {
match element.name() {
PUBLISH => action = Some(Action::Publish),
WITHDRAW => action = Some(Action::Withdraw),
Expand All @@ -1137,7 +1142,7 @@ pub trait ProcessDelta {
}
_ => Err(ProcessError::malformed())
})
})?;
}, MAX_FILE_SIZE)?;
let mut inner = match inner {
Some(inner) => inner,
None => break
Expand Down

0 comments on commit 32a55fe

Please sign in to comment.