- struct integrity_table *table = NULL;
- int ret = 0;
- u64 expected_size;
- u64 expected_num_entries;
-
- if (res_entry->original_size < 12) {
- ERROR("Integrity table is too short (expected at least 12 bytes)");
- ret = WIMLIB_ERR_INVALID_INTEGRITY_TABLE;
- goto out;
- }
-
- if (res_entry->flags & WIM_RESHDR_FLAG_COMPRESSED) {
- ERROR("Didn't expect a compressed integrity table");
- ret = WIMLIB_ERR_INVALID_INTEGRITY_TABLE;
- goto out;
- }
-
- /* Read the integrity table into memory. */
- if ((sizeof(size_t) < sizeof(u64)
- && res_entry->size > ~(size_t)0)
- || ((table = MALLOC(res_entry->size)) == NULL))
- {
- ERROR("Out of memory (needed %zu bytes for integrity table)",
- (size_t)res_entry->size);
- ret = WIMLIB_ERR_NOMEM;
- goto out;
- }
-
- ret = read_uncompressed_resource(fp, res_entry->offset,
- res_entry->size, (void*)table);
-
- if (ret != 0) {
- ERROR("Failed to read integrity table (size = %"PRIu64", "
- " offset = %"PRIu64")",
- (u64)res_entry->size, res_entry->offset);
- goto out;
- }
-
- table->size = le32_to_cpu(table->size);
- table->num_entries = le32_to_cpu(table->num_entries);
- table->chunk_size = le32_to_cpu(table->chunk_size);
-
- if (table->size != res_entry->size) {
- ERROR("Inconsistent integrity table sizes: Table header says "
- "%u bytes but resource entry says %"PRIu64" bytes",
- table->size, (u64)res_entry->size);
- ret = WIMLIB_ERR_INVALID_INTEGRITY_TABLE;
- goto out;
- }