- if (!w->xml_data)
- return WIMLIB_ERR_INVALID_PARAM;
- bytes_written = fwrite(w->xml_data, 1, w->hdr.xml_res_entry.size, fp);
- if (bytes_written != w->hdr.xml_res_entry.size) {
+ size = w->hdr.xml_res_entry.size;
+ if (sizeof(size_t) < sizeof(u64))
+ if (size != w->hdr.xml_res_entry.size)
+ return WIMLIB_ERR_INVALID_PARAM;
+
+ buf = MALLOC(size);
+ if (!buf)
+ return WIMLIB_ERR_NOMEM;
+
+ if (full_pread(w->in_fd,
+ buf,
+ w->hdr.xml_res_entry.size,
+ w->hdr.xml_res_entry.offset) != w->hdr.xml_res_entry.size)
+ {
+ ERROR_WITH_ERRNO("Error reading XML data");
+ ret = WIMLIB_ERR_READ;
+ goto out_free_buf;
+ }
+
+ if (fwrite(buf, 1, size, fp) != size) {