Skip to content

Commit

Permalink
core: Correctly handle empty dirtabs with nonzero size (#66)
Browse files Browse the repository at this point in the history
  • Loading branch information
antangelo authored Dec 1, 2023
1 parent cdc4f48 commit 2bbf8f7
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
4 changes: 2 additions & 2 deletions xdvdfs-core/src/read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ async fn read_dirent<E>(
.await
.map_err(|e| util::Error::IOError(e))?;

// Empty directory entries are filled with 0xff
if dirent_buf == [0xff; 0xe] {
// Empty directory entries are filled with 0xff or 0x00
if dirent_buf == [0xff; 0xe] || dirent_buf == [0x00; 0xe] {
return Ok(None);
}

Expand Down
2 changes: 1 addition & 1 deletion xdvdfs-core/src/write/avl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,7 @@ mod test {
fn test_preorder_backend_ordering_large_data() {
let mut rng = rngs::StdRng::seed_from_u64(0x5842_4f58_5842_4f58);
let mut test_set: Vec<i32> = Vec::new();
test_set.resize_with(100, || rng.gen());
test_set.resize_with(1000, || rng.gen());

let mut tree = AvlTree::default();

Expand Down
7 changes: 7 additions & 0 deletions xdvdfs-core/src/write/dirtab.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,13 @@ impl DirectoryEntryTableWriter {
mut self,
allocator: &mut SectorAllocator,
) -> Result<DirectoryEntryTableDiskRepr, util::Error<E>> {
if self.table.backing_vec().is_empty() {
return Ok(DirectoryEntryTableDiskRepr {
entry_table: alloc::vec![0xff; 2048].into_boxed_slice(),
file_listing: Vec::new(),
});
}

self.table.reorder_backing_preorder();

// Array of offsets for each entry in the table
Expand Down

0 comments on commit 2bbf8f7

Please sign in to comment.