mirror of
https://github.com/lifegpc/msg-tool.git
synced 2026-06-25 13:17:06 +08:00
Fix some overflow problem
This commit is contained in:
@@ -354,7 +354,7 @@ fn is_this_format_name_len(buf: &[u8], name_len: usize) -> Result<u8> {
|
|||||||
}
|
}
|
||||||
let first_size = reader.cpeek_u32_at(name_len as u64)?;
|
let first_size = reader.cpeek_u32_at(name_len as u64)?;
|
||||||
let second_offset = reader.cpeek_u32_at(8 + name_len as u64 * 2)?;
|
let second_offset = reader.cpeek_u32_at(8 + name_len as u64 * 2)?;
|
||||||
if second_offset - next_offset == first_size {
|
if second_offset < next_offset || second_offset - next_offset == first_size {
|
||||||
return Err(anyhow::anyhow!("Invalid second_offset in DAT archive"));
|
return Err(anyhow::anyhow!("Invalid second_offset in DAT archive"));
|
||||||
}
|
}
|
||||||
for i in 0..mcount {
|
for i in 0..mcount {
|
||||||
|
|||||||
@@ -480,7 +480,12 @@ pub fn is_this_format(buf: &[u8]) -> Result<u8> {
|
|||||||
while index < avail_count {
|
while index < avail_count {
|
||||||
let off = reader.read_u32()?;
|
let off = reader.read_u32()?;
|
||||||
let size = reader.read_u32()?;
|
let size = reader.read_u32()?;
|
||||||
if off < prev_off || prev_off + prev_size != off {
|
if off < prev_off
|
||||||
|
|| prev_off
|
||||||
|
.checked_add(prev_size)
|
||||||
|
.ok_or_else(|| anyhow::anyhow!("Overflow in offset calculation"))?
|
||||||
|
!= off
|
||||||
|
{
|
||||||
return Err(anyhow::anyhow!("Invalid offset."));
|
return Err(anyhow::anyhow!("Invalid offset."));
|
||||||
}
|
}
|
||||||
prev_off = off;
|
prev_off = off;
|
||||||
|
|||||||
Reference in New Issue
Block a user