]> wimlib.net Git - wimlib/blobdiff - src/integrity.c
Rewritten functions for reading and writing resources
[wimlib] / src / integrity.c
index 49fe514c7300f8dc42bcb4446da2a95a364263b6..12968bf91004a0b2e54d6b59c677c5e8c5f261c2 100644 (file)
@@ -50,7 +50,7 @@ static int verify_integrity(FILE *fp, u64 num_bytes, u32 chunk_size,
                            int *status)
 {
        char  *chunk_buf;
-       u8     resblock[WIM_HASH_SIZE];
+       u8     resblock[SHA1_HASH_SIZE];
        u64    bytes_remaining;
        size_t bytes_to_read;
        uint   percent_done;
@@ -85,11 +85,11 @@ static int verify_integrity(FILE *fp, u64 num_bytes, u32 chunk_size,
                        goto verify_integrity_error;
                }
                sha1_buffer(chunk_buf, bytes_to_read, resblock);
-               if (memcmp(resblock, sha1sums, WIM_HASH_SIZE) != 0) {
+               if (!hashes_equal(resblock, sha1sums)) {
                        *status = WIM_INTEGRITY_NOT_OK;
                        goto verify_integrity_done;
                }
-               sha1sums += WIM_HASH_SIZE;
+               sha1sums += SHA1_HASH_SIZE;
                bytes_remaining -= bytes_to_read;
        }
        *status = WIM_INTEGRITY_OK;
@@ -135,11 +135,14 @@ int check_wim_integrity(WIMStruct *w, int show_progress, int *status)
                *status = WIM_INTEGRITY_NONEXISTENT;
                return 0;
        }
-       ctype = wim_resource_compression_type(w, res_entry);
        if (res_entry->original_size < 12) {
                ERROR("Integrity table is too short");
                return WIMLIB_ERR_INVALID_INTEGRITY_TABLE;
        }
+       if (res_entry->flags & WIM_RESHDR_FLAG_COMPRESSED) {
+               ERROR("Didn't expect a compressed integrity table");
+               return WIMLIB_ERR_INVALID_INTEGRITY_TABLE;
+       }
 
        /* Read the integrity table into memory. */
        buf = MALLOC(res_entry->original_size);
@@ -149,15 +152,14 @@ int check_wim_integrity(WIMStruct *w, int show_progress, int *status)
                ret = WIMLIB_ERR_NOMEM;
                goto out;
        }
-       ret = read_full_resource(w->fp, res_entry->size,
-                                res_entry->original_size,
-                                res_entry->offset, ctype, buf);
+       ret = read_uncompressed_resource(w->fp, res_entry->offset,
+                                        res_entry->original_size, buf);
        if (ret != 0) {
                ERROR("Failed to read integrity table (size = %"PRIu64", "
                      "original_size = %"PRIu64", offset = "
-                     "%"PRIu64", ctype = %d",
+                     "%"PRIu64")",
                      (u64)res_entry->size, res_entry->original_size,
-                     res_entry->offset, ctype);
+                     res_entry->offset);
                goto out;
        }
 
@@ -181,7 +183,7 @@ int check_wim_integrity(WIMStruct *w, int show_progress, int *status)
              integrity_table_size, num_entries, chunk_size);
 
 
-       expected_size = num_entries * WIM_HASH_SIZE + 12;
+       expected_size = num_entries * SHA1_HASH_SIZE + 12;
 
        if (integrity_table_size != expected_size) {
                ERROR("Integrity table is %u bytes, but expected %"PRIu64" "
@@ -209,8 +211,7 @@ int check_wim_integrity(WIMStruct *w, int show_progress, int *status)
                      "the %"PRIu64" bytes from the end of the header to the",
                      expected_num_entries, bytes_to_check);
                ERROR("end of the lookup table with a chunk size of %u, but "
-                     "there were only %u entries", expected_num_entries,
-                     bytes_to_check, chunk_size, num_entries);
+                     "there were only %u entries", chunk_size, num_entries);
                ret = WIMLIB_ERR_INVALID_INTEGRITY_TABLE;
                goto out;
        }
@@ -265,7 +266,7 @@ int write_integrity_table(FILE *out, u64 end_header_offset,
        bytes_to_check = end_lookup_table_offset - end_header_offset;
        num_entries = bytes_to_check / INTEGRITY_CHUNK_SIZE +
                        (bytes_to_check % INTEGRITY_CHUNK_SIZE != 0);
-       integrity_table_size = num_entries * WIM_HASH_SIZE + 3 * sizeof(u32);
+       integrity_table_size = num_entries * SHA1_HASH_SIZE + 3 * sizeof(u32);
 
        DEBUG("integrity table size = %u", integrity_table_size);
 
@@ -322,7 +323,7 @@ int write_integrity_table(FILE *out, u64 end_header_offset,
                        goto err2;
                }
                sha1_buffer(chunk_buf, bytes_read, p);
-               p += WIM_HASH_SIZE;
+               p += SHA1_HASH_SIZE;
                bytes_remaining -= bytes_read;
        }
        if (show_progress)