stricter parsing of file version

This commit is contained in:
MaxOhn
2023-02-09 07:37:09 +01:00
parent a96a6b8ee0
commit 16e06e50b7
+8 -5
View File
@@ -138,12 +138,15 @@ impl<R> FileReader<R> {
.and_then(|idx| {
self.buf[idx..]
.starts_with(b"osu file format v")
.then_some(idx + 17)
.then_some(self.buf[idx + 17..].iter())
})
.map(|idx| {
let mut n = 0;
.and_then(|mut num| {
let mut n = num
.next()
.filter(|byte| (b'0'..=b'9').contains(byte))
.map(|&byte| byte & 0xF)?;
for byte in &self.buf[idx..] {
for byte in num {
if !(b'0'..=b'9').contains(byte) {
break;
}
@@ -151,7 +154,7 @@ impl<R> FileReader<R> {
n = 10 * n + (*byte & 0xF);
}
n
Some(n)
})
.ok_or(ParseError::IncorrectFileHeader)
}