#include "wimlib/types.h"
#include "wimlib/endianness.h"
+#include <limits.h>
+
/* Length of "Globally Unique ID" field in WIM header. */
#define WIM_GUID_LEN 16
/* +0xd0 (208) */
} _packed_attribute;
+#define MAX_IMAGES (((INT_MAX < INT32_MAX) ? INT_MAX : INT32_MAX) - 1)
/* In-memory representation of a WIM header. See `struct wim_header_disk' for
* field descriptions. */
DEBUG("part_number = %u, total_parts = %u, image_count = %u",
hdr->part_number, hdr->total_parts, hdr->image_count);
- if (hdr->image_count >= INT_MAX) {
+ if (unlikely(hdr->image_count > MAX_IMAGES)) {
ERROR("\"%"TS"\": Invalid image count (%u)",
filename, hdr->image_count);
return WIMLIB_ERR_IMAGE_COUNT;
num_images = 0;
for_node_child(wim_node, child) {
if (node_is_element(child) && node_name_is(child, "IMAGE")) {
- if (num_images == INT_MAX) {
- return WIMLIB_ERR_IMAGE_COUNT;
+ if (unlikely(num_images == MAX_IMAGES)) {
+ ret = WIMLIB_ERR_IMAGE_COUNT;
+ goto err;
}
num_images++;
}
ERROR("WIM images are not indexed [1...%d] "
"in XML data as expected",
num_images);
- return WIMLIB_ERR_IMAGE_COUNT;
+ ret = WIMLIB_ERR_IMAGE_COUNT;
+ goto err;
}
}