[core] fix size check for VHD images

* Recent changes broke the check for whether the source image is larger than the target drive
  in the case of uncompressed VHDs (that have a 512 byte footer), so fix that by making sure
  we always compare with the projected size.
* Closes #2729.
* Also fix some more Coverity warnings.
This commit is contained in:
Pete Batard 2025-05-07 13:35:48 +01:00
parent 965759f58a
commit 13c6becf42
No known key found for this signature in database
GPG key ID: 38E0CF5E69EDD671
5 changed files with 18 additions and 8 deletions

View file

@ -1451,7 +1451,7 @@ static DWORD WINAPI BootCheckThread(LPVOID param)
if (boot_type == BT_IMAGE) { if (boot_type == BT_IMAGE) {
if_not_assert(image_path != NULL) if_not_assert(image_path != NULL)
goto out; goto out;
if ((size_check) && (MAX(img_report.image_size, img_report.projected_size) > (uint64_t)SelectedDrive.DiskSize)) { if ((size_check) && (img_report.projected_size > (uint64_t)SelectedDrive.DiskSize)) {
// This ISO image is too big for the selected target // This ISO image is too big for the selected target
MessageBoxExU(hMainDialog, lmprintf(MSG_089), lmprintf(MSG_088), MB_OK | MB_ICONERROR | MB_IS_RTL, selected_langid); MessageBoxExU(hMainDialog, lmprintf(MSG_089), lmprintf(MSG_088), MB_OK | MB_ICONERROR | MB_IS_RTL, selected_langid);
goto out; goto out;

View file

@ -33,7 +33,7 @@ LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL
IDD_DIALOG DIALOGEX 12, 12, 232, 326 IDD_DIALOG DIALOGEX 12, 12, 232, 326
STYLE DS_SETFONT | DS_MODALFRAME | DS_CENTER | WS_MINIMIZEBOX | WS_POPUP | WS_CAPTION | WS_SYSMENU STYLE DS_SETFONT | DS_MODALFRAME | DS_CENTER | WS_MINIMIZEBOX | WS_POPUP | WS_CAPTION | WS_SYSMENU
EXSTYLE WS_EX_ACCEPTFILES EXSTYLE WS_EX_ACCEPTFILES
CAPTION "Rufus 4.8.2242" CAPTION "Rufus 4.8.2243"
FONT 9, "Segoe UI Symbol", 400, 0, 0x0 FONT 9, "Segoe UI Symbol", 400, 0, 0x0
BEGIN BEGIN
LTEXT "Drive Properties",IDS_DRIVE_PROPERTIES_TXT,8,6,53,12,NOT WS_GROUP LTEXT "Drive Properties",IDS_DRIVE_PROPERTIES_TXT,8,6,53,12,NOT WS_GROUP
@ -407,8 +407,8 @@ END
// //
VS_VERSION_INFO VERSIONINFO VS_VERSION_INFO VERSIONINFO
FILEVERSION 4,8,2242,0 FILEVERSION 4,8,2243,0
PRODUCTVERSION 4,8,2242,0 PRODUCTVERSION 4,8,2243,0
FILEFLAGSMASK 0x3fL FILEFLAGSMASK 0x3fL
#ifdef _DEBUG #ifdef _DEBUG
FILEFLAGS 0x1L FILEFLAGS 0x1L
@ -426,13 +426,13 @@ BEGIN
VALUE "Comments", "https://rufus.ie" VALUE "Comments", "https://rufus.ie"
VALUE "CompanyName", "Akeo Consulting" VALUE "CompanyName", "Akeo Consulting"
VALUE "FileDescription", "Rufus" VALUE "FileDescription", "Rufus"
VALUE "FileVersion", "4.8.2242" VALUE "FileVersion", "4.8.2243"
VALUE "InternalName", "Rufus" VALUE "InternalName", "Rufus"
VALUE "LegalCopyright", "© 2011-2025 Pete Batard (GPL v3)" VALUE "LegalCopyright", "© 2011-2025 Pete Batard (GPL v3)"
VALUE "LegalTrademarks", "https://www.gnu.org/licenses/gpl-3.0.html" VALUE "LegalTrademarks", "https://www.gnu.org/licenses/gpl-3.0.html"
VALUE "OriginalFilename", "rufus-4.8.exe" VALUE "OriginalFilename", "rufus-4.8.exe"
VALUE "ProductName", "Rufus" VALUE "ProductName", "Rufus"
VALUE "ProductVersion", "4.8.2242" VALUE "ProductVersion", "4.8.2243"
END END
END END
BLOCK "VarFileInfo" BLOCK "VarFileInfo"

View file

@ -186,6 +186,8 @@ int8_t IsBootableImage(const char* path)
goto out; goto out;
} }
img_report.image_size = (uint64_t)liImageSize.QuadPart; img_report.image_size = (uint64_t)liImageSize.QuadPart;
if (img_report.projected_size == 0)
img_report.projected_size = img_report.image_size;
size = sizeof(wim_magic); size = sizeof(wim_magic);
IGNORE_RETVAL(SetFilePointerEx(handle, ptr, NULL, FILE_BEGIN)); IGNORE_RETVAL(SetFilePointerEx(handle, ptr, NULL, FILE_BEGIN));
img_report.is_windows_img = ReadFile(handle, &wim_magic, size, &size, NULL) && (wim_magic == WIM_MAGIC); img_report.is_windows_img = ReadFile(handle, &wim_magic, size, &size, NULL) && (wim_magic == WIM_MAGIC);

View file

@ -59,6 +59,7 @@
* optimizations. * optimizations.
*/ */
#include "wimlib/assert.h"
#include "wimlib/bitops.h" #include "wimlib/bitops.h"
#include "wimlib/compress_common.h" #include "wimlib/compress_common.h"
#include "wimlib/compressor_ops.h" #include "wimlib/compressor_ops.h"
@ -504,6 +505,8 @@ xpress_record_match(struct xpress_compressor *c, unsigned length, unsigned offse
unsigned log2_offset = bsr32(offset); unsigned log2_offset = bsr32(offset);
unsigned sym = XPRESS_NUM_CHARS + ((log2_offset << 4) | len_hdr); unsigned sym = XPRESS_NUM_CHARS + ((log2_offset << 4) | len_hdr);
wimlib_assert(sym < XPRESS_NUM_SYMBOLS);
// coverity[overrun-local]
c->freqs[sym]++; c->freqs[sym]++;
return (struct xpress_item) { return (struct xpress_item) {
@ -759,6 +762,8 @@ xpress_tally_item_list(struct xpress_compressor *c,
len_hdr = min(0xF, adjusted_len); len_hdr = min(0xF, adjusted_len);
sym = XPRESS_NUM_CHARS + ((log2_offset << 4) | len_hdr); sym = XPRESS_NUM_CHARS + ((log2_offset << 4) | len_hdr);
wimlib_assert(sym < XPRESS_NUM_SYMBOLS);
// coverity[overrun-local]
c->freqs[sym]++; c->freqs[sym]++;
} }
cur_node += length; cur_node += length;
@ -872,6 +877,8 @@ xpress_find_min_cost_path(struct xpress_compressor *c, size_t in_nbytes,
len_hdr = min(adjusted_len, 0xF); len_hdr = min(adjusted_len, 0xF);
sym = XPRESS_NUM_CHARS + sym = XPRESS_NUM_CHARS +
((log2_offset << 4) | len_hdr); ((log2_offset << 4) | len_hdr);
wimlib_assert(sym < XPRESS_NUM_SYMBOLS);
// coverity[overrun-local]
cost_to_end = cost_to_end =
offset_cost + c->costs[sym] + offset_cost + c->costs[sym] +
(cur_node + len)->cost_to_end; (cur_node + len)->cost_to_end;

View file

@ -240,6 +240,7 @@ char *ezxml_decode(char *s, char **ent, char t)
l = (d = (long)(s - r)) + c + (long)(e ? strlen(e) : 0); // new length l = (d = (long)(s - r)) + c + (long)(e ? strlen(e) : 0); // new length
r = (r == m) ? strcpy(malloc(l), r) : _realloc(r, l); r = (r == m) ? strcpy(malloc(l), r) : _realloc(r, l);
e = strchr((s = r + d), ';'); // fix up pointers e = strchr((s = r + d), ';'); // fix up pointers
if (!e) return r;
} }
memmove(s + c, e + 1, strlen(e)); // shift rest of string memmove(s + c, e + 1, strlen(e)); // shift rest of string
@ -680,7 +681,7 @@ ezxml_t ezxml_parse_fd(int fd)
{ {
ezxml_root_t root; ezxml_root_t root;
struct stat st; struct stat st;
size_t l; ssize_t l;
void *m; void *m;
if (fd < 0 || fstat(fd, &st)) return NULL; if (fd < 0 || fstat(fd, &st)) return NULL;
@ -696,7 +697,7 @@ ezxml_t ezxml_parse_fd(int fd)
} }
else { // mmap failed, read file into memory else { // mmap failed, read file into memory
#endif // EZXML_NOMMAP #endif // EZXML_NOMMAP
l = (long)_read(fd, m = malloc((size_t)st.st_size), (unsigned int)st.st_size); l = (ssize_t)_read(fd, m = malloc((size_t)st.st_size), (unsigned int)st.st_size);
if (l < 0) { free(m); return NULL; }; if (l < 0) { free(m); return NULL; };
root = (ezxml_root_t)ezxml_parse_str(m, l); root = (ezxml_root_t)ezxml_parse_str(m, l);
if (!root) { free(m); return NULL; }; if (!root) { free(m); return NULL; };