Skip to content

Commit 8f31a80

Browse files
committed
.all archives only need alignment once
found this while sanity-checking a claim in the blog post lol
1 parent d813e48 commit 8f31a80

1 file changed

Lines changed: 8 additions & 7 deletions

File tree

rust/src/crazytaxi/archive.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,12 @@ impl<'a> ArchiveReader<'a> {
3232
pub fn new(data: &'a [u8]) -> Result<Self> {
3333
let mut reader = Reader::new(Cursor::new(data));
3434
let header = AllHeader::from_reader_with_ctx(&mut reader, ())?;
35-
let offset = reader.stream_position()? as usize;
35+
let mut offset = reader.stream_position()? as usize;
36+
if offset % 0x20 != 0 {
37+
// entries are aligned to 0x20 sized blocks
38+
let diff = 0x20 - (offset % 0x20);
39+
offset += diff;
40+
}
3641
Ok(ArchiveReader {
3742
data,
3843
header,
@@ -53,13 +58,9 @@ impl<'a> Iterator for ArchiveReader<'a> {
5358

5459
fn next(&mut self) -> Option<Self::Item> {
5560
let item = self.header.items.get(self.item_idx)?;
56-
let mut entry_offset = self.offset;
61+
let entry_offset = self.offset;
5762
let entry_size = item.size as usize;
58-
if entry_offset % 0x20 != 0 {
59-
// entries are aligned to 0x20 sized blocks
60-
let diff = 0x20 - (self.offset % 0x20);
61-
entry_offset += diff;
62-
}
63+
assert_eq!(entry_offset % 0x20, 0, "archive entry not aligned to 0x20 bytes");
6364

6465
self.item_idx += 1;
6566
self.offset += item.size as usize;

0 commit comments

Comments
 (0)