- if (!(open_flags & WIMLIB_OPEN_FLAG_SPLIT_OK)
- && (hdr->part_number != 1 || hdr->total_parts != 1))
+ if (hdr->total_parts == 0 ||
+ hdr->part_number == 0 ||
+ hdr->part_number > hdr->total_parts)
+ {
+ ERROR("Invalid WIM part number: %hu of %hu",
+ hdr->part_number, hdr->total_parts);
+ return WIMLIB_ERR_INVALID_PART_NUMBER;
+ }
+
+ if (!(open_flags & WIMLIB_OPEN_FLAG_SPLIT_OK) &&
+ hdr->total_parts != 1)