+
+ if (cur_entry->part_number != w->hdr.part_number) {
+ ERROR("A lookup table entry in part %hu of the WIM "
+ "points to part %hu",
+ w->hdr.part_number, cur_entry->part_number);
+ ret = WIMLIB_ERR_INVALID_LOOKUP_TABLE_ENTRY;
+ goto out_free_cur_entry;
+ }
+
+ if (is_zero_hash(cur_entry->hash)) {
+ ERROR("The WIM lookup table contains an entry with a "
+ "SHA1 message digest of all 0's");
+ ret = WIMLIB_ERR_INVALID_LOOKUP_TABLE_ENTRY;
+ goto out_free_cur_entry;
+ }
+
+ if (!(cur_entry->resource_entry.flags & WIM_RESHDR_FLAG_COMPRESSED)
+ && (cur_entry->resource_entry.size !=
+ cur_entry->resource_entry.original_size))
+ {
+ #ifdef ENABLE_ERROR_MESSAGES
+ ERROR("Found uncompressed resource with original size "
+ "not the same as compressed size");
+ ERROR("The lookup table entry for the resource is as follows:");
+ print_lookup_table_entry(cur_entry, stderr);
+ #endif
+ ret = WIMLIB_ERR_INVALID_LOOKUP_TABLE_ENTRY;
+ goto out_free_cur_entry;
+ }
+
+ if (cur_entry->resource_entry.flags & WIM_RESHDR_FLAG_METADATA) {
+ /* Lookup table entry for a metadata resource */
+ if (cur_entry->refcnt != 1) {
+ #ifdef ENABLE_ERROR_MESSAGES
+ ERROR("Found metadata resource with refcnt != 1:");
+ print_lookup_table_entry(cur_entry, stderr);
+ #endif
+ ret = WIMLIB_ERR_INVALID_LOOKUP_TABLE_ENTRY;
+ goto out_free_cur_entry;
+ }
+
+ if (w->hdr.part_number != 1) {
+ ERROR("Found a metadata resource in a "
+ "non-first part of the split WIM!");
+ ret = WIMLIB_ERR_INVALID_LOOKUP_TABLE_ENTRY;
+ goto out_free_cur_entry;
+ }
+ if (w->current_image == w->hdr.image_count) {
+ ERROR("The WIM header says there are %u images "
+ "in the WIM, but we found more metadata "
+ "resources than this", w->hdr.image_count);
+ ret = WIMLIB_ERR_IMAGE_COUNT;
+ goto out_free_cur_entry;
+ }
+
+ /* Notice very carefully: We are assigning the metadata
+ * resources in the exact order mirrored by their lookup
+ * table entries on disk, which is the behavior of
+ * Microsoft's software. In particular, this overrides
+ * the actual locations of the metadata resources
+ * themselves in the WIM file as well as any information
+ * written in the XML data. */
+ DEBUG("Found metadata resource for image %u at "
+ "offset %"PRIu64".",
+ w->current_image + 1,
+ cur_entry->resource_entry.offset);
+ w->image_metadata[
+ w->current_image++]->metadata_lte = cur_entry;
+ } else {
+ /* Lookup table entry for a stream that is not a
+ * metadata resource */
+ duplicate_entry = __lookup_resource(table, cur_entry->hash);
+ if (duplicate_entry) {
+ #ifdef ENABLE_ERROR_MESSAGES
+ ERROR("The WIM lookup table contains two entries with the "
+ "same SHA1 message digest!");
+ ERROR("The first entry is:");
+ print_lookup_table_entry(duplicate_entry, stderr);
+ ERROR("The second entry is:");
+ print_lookup_table_entry(cur_entry, stderr);
+ #endif
+ ret = WIMLIB_ERR_INVALID_LOOKUP_TABLE_ENTRY;
+ goto out_free_cur_entry;
+ }
+ lookup_table_insert(table, cur_entry);
+ }
+ }
+
+ if (w->hdr.part_number == 1 &&
+ w->current_image != w->hdr.image_count)
+ {
+ ERROR("The WIM header says there are %u images "
+ "in the WIM, but we only found %d metadata "
+ "resources!", w->hdr.image_count, w->current_image);
+ ret = WIMLIB_ERR_IMAGE_COUNT;
+ goto out_free_lookup_table;