From 947670d992454033a13c70e36a53a2ac10b3d6ad Mon Sep 17 00:00:00 2001 From: David Oberhollenzer Date: Tue, 23 Mar 2021 11:32:04 +0100 Subject: block processor: Re-implement exact fragment matching In the hash-table equals callback, if the hash and size match, do an exact, byte-for-byte comparison of the fragment in question. The fragment can either be in a fragment block that is in-flight (for which we have the in-flight list), in the current, unfinished fragment block, or it can be on disk. In the later case, the fragment block is resolved through the fragment table and read back from disk into a scratch buffer and decompressed. After that, the fragment is checked for byte-for-byte equality with the one we resolved through the hash table. Signed-off-by: David Oberhollenzer --- lib/sqfs/block_processor/backend.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'lib/sqfs/block_processor/backend.c') diff --git a/lib/sqfs/block_processor/backend.c b/lib/sqfs/block_processor/backend.c index d71c632..f81304b 100644 --- a/lib/sqfs/block_processor/backend.c +++ b/lib/sqfs/block_processor/backend.c @@ -152,8 +152,16 @@ static int process_completed_fragment(sqfs_block_processor_t *proc, search.hash = frag->checksum; search.size = frag->size; + proc->current_frag = frag; + proc->fblk_lookup_error = 0; entry = hash_table_search_pre_hashed(proc->frag_ht, search.hash, &search); + proc->current_frag = NULL; + + if (proc->fblk_lookup_error != 0) { + err = proc->fblk_lookup_error; + goto fail; + } if (entry != NULL) { if (frag->inode != NULL) { @@ -219,8 +227,16 @@ static int process_completed_fragment(sqfs_block_processor_t *proc, chunk->size = frag->size; chunk->hash = frag->checksum; + proc->current_frag = frag; + proc->fblk_lookup_error = 0; entry = hash_table_insert_pre_hashed(proc->frag_ht, chunk->hash, chunk, chunk); + proc->current_frag = NULL; + + if (proc->fblk_lookup_error != 0) { + err = proc->fblk_lookup_error; + goto fail; + } if (entry == NULL) goto fail; -- cgit v1.2.3