- if (!split_ok && (hdr->part_number != 1 || hdr->total_parts != 1)) {
- ERROR("This WIM is part %u of a %u-part WIM.\n",
- hdr->part_number, hdr->total_parts);
+ 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->part_number != 1 || hdr->total_parts != 1))
+ {
+ ERROR("This WIM is part %u of a %u-part WIM",
+ hdr->part_number, hdr->total_parts);