Skip to content

Commit

Permalink
Wrote/updated some TODOs, skeleton of generate_fragmentations
Browse files Browse the repository at this point in the history
  • Loading branch information
Will-Banksy committed Apr 4, 2024
1 parent 30ee128 commit 264aae6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
11 changes: 9 additions & 2 deletions libsearchlight/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ pub mod iter;
pub mod str_parse;
pub mod fragments_index;

use std::{collections::BTreeMap, fs::File, io::{self, Seek}};
use std::{collections::BTreeMap, fs::File, io::{self, Seek}, ops::Range};

use crate::search::Match;
use crate::{search::Match, validation::Fragment};

#[cfg(test)]
pub fn init_test_logger() {
Expand Down Expand Up @@ -87,6 +87,13 @@ pub fn estimate_cluster_size<'a>(headers: impl IntoIterator<Item = &'a Match>) -
}
}

/// Generates a list of lists of fragments, as candidates for reconstructing fragmented data in `fragmentation_range`. That is, for fragmented data in
/// `fragmentation_range`, occupying a known `num_file_clusters` clusters, and being broken into `num_fragments` fragments, this function will generate
/// all possible arrangements of clusters that the fragmented data can occupy, assuming that the fragmented data is in-order.
fn generate_fragmentations(file_data: &[u8], cluster_size: usize, fragmentation_range: Range<usize>, num_file_clusters: usize, num_fragments: usize) -> Vec<Vec<Fragment>> {
todo!() // TODO: Implement an algorithm to do as described in the doc comment. Look at https://doi.org/10.1016/j.diin.2019.04.014 for inspiration if need be
}

#[cfg(test)]
mod test {
use crate::{search::Match, utils::estimate_cluster_size};
Expand Down
8 changes: 6 additions & 2 deletions libsearchlight/src/validation/png.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,8 @@ impl PngValidator {
// Load the (what we assume is) the CRC
let stored_crc = u32::from_be_bytes(file_data[(next_chunk_type_offset - 8)..(next_chunk_type_offset - 4)].try_into().unwrap());

// TODO: Check these below calculations

// Calculate the fragmentation points
let fragmentation_start = utils::next_multiple_of(chunk_idx as u64 + 8, cluster_size) as usize;
let fragmentation_end = utils::prev_multiple_of(next_chunk_type_offset as u64 - 8, cluster_size) as usize;
Expand All @@ -245,8 +247,10 @@ impl PngValidator {
assert_eq!((next_chunk_type_offset - (unfrag_crc_offset + 8)) % cluster_size as usize, 0);
assert_eq!((fragmentation_end - fragmentation_start) % cluster_size as usize, 0);

// TODO: We've found the next chunk type (hopefully). Now, decode the stored CRC, and find the arrangements of clusters from the fragmentation start point to this point
// that result in the calculated CRC matching the decoded CRC
// TODO: Use utils::generate_fragmentations (once implemented) and calculate the CRC over each fragmentation (including data outside of the fragmentation
// area, like the chunk type and data in the same cluster) to find one that matches the stored CRC. If none can be found, return a failure

// utils::generate_fragmentations

todo!()
}
Expand Down

0 comments on commit 264aae6

Please sign in to comment.