Skip to content

Commit 3d5ab84

Browse files
committed
[iso] fix FAT filenames being truncated on image extraction
* Needed to read 12 chars instead of stopping at 11 and therefore inserting a NUL. * Closes #2534. * Also enable detection of bootriscv64.efi and bootloongarch64.efi bootloaders from FAT images.
1 parent 8d1ed44 commit 3d5ab84

File tree

4 files changed

+32
-29
lines changed

4 files changed

+32
-29
lines changed

src/iso.c

+12-17
Original file line numberDiff line numberDiff line change
@@ -1758,8 +1758,8 @@ BOOL HasEfiImgBootLoaders(void)
17581758
int32_t dc, c;
17591759
struct libfat_filesystem *lf_fs = NULL;
17601760
struct libfat_direntry direntry;
1761-
char name[12] = { 0 }, bootloader_name[32];
1762-
int i, j, k;
1761+
char bootloader_name[16];
1762+
int i;
17631763

17641764
if ((image_path == NULL) || !HAS_EFI_IMG(img_report))
17651765
return FALSE;
@@ -1799,24 +1799,19 @@ BOOL HasEfiImgBootLoaders(void)
17991799
goto out;
18001800
dc = direntry.entry[26] + (direntry.entry[27] << 8);
18011801

1802-
for (i = 0; i < ARRAYSIZE(efi_archname); i++) {
1803-
static_sprintf(bootloader_name, "boot%s.efi", efi_archname[i]);
1804-
// TODO: bootriscv64.efi and bootloongarch64.efi need LFN support
1805-
if (strlen(bootloader_name) > 12)
1806-
continue;
1807-
for (j = 0, k = 0; bootloader_name[j] != 0; j++) {
1808-
if (bootloader_name[j] == '.') {
1809-
while (k < 8)
1810-
name[k++] = ' ';
1811-
} else {
1812-
name[k++] = toupper(bootloader_name[j]);
1813-
}
1814-
}
1815-
c = libfat_searchdir(lf_fs, dc, name, &direntry);
1802+
for (i = 1; i < ARRAYSIZE(efi_archname); i++) {
1803+
// We consider it unlikely that any bootri#####.efi or bootlo#####.efi files
1804+
// in the /efi/boot/ subdirectory will be anything but 'bootriscv64.efi' and
1805+
// 'bootloongarch64.efi', so we'll use the ~1 LFN shortened names for them.
1806+
static_sprintf(bootloader_name, "BOOT%c%c%c%cEFI", efi_archname[i][0], efi_archname[i][1],
1807+
strlen(efi_archname[i]) > 4 ? '~' : efi_archname[i][2],
1808+
strlen(efi_archname[i]) > 4 ? '1' : (strlen(efi_archname[i]) > 3 ? efi_archname[i][3] : ' '));
1809+
safe_strtoupper(bootloader_name);
1810+
c = libfat_searchdir(lf_fs, dc, bootloader_name, &direntry);
18161811
if (c > 0) {
18171812
if (!ret)
18181813
uprintf(" Detected EFI bootloader(s) (from '%s'):", img_report.efi_img_path);
1819-
uprintf(" ● '%s'", bootloader_name);
1814+
uprintf(" ● 'boot%s.efi'", efi_archname[i]);
18201815
ret = TRUE;
18211816
}
18221817
}

src/rufus.h

+1
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ static __inline void safe_strcp(char* dst, const size_t dst_max, const char* src
184184
#define safe_vsnprintf vsnprintf
185185
#endif
186186
#define safe_strtolower(str) do { if (str != NULL) CharLowerA(str); } while(0)
187+
#define safe_strtoupper(str) do { if (str != NULL) CharUpperA(str); } while(0)
187188
static __inline void static_repchr(char* p, char s, char r) {
188189
if (p != NULL) while (*p != 0) { if (*p == s) *p = r; p++; }
189190
}

src/rufus.rc

+5-5
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL
3333
IDD_DIALOG DIALOGEX 12, 12, 232, 326
3434
STYLE DS_SETFONT | DS_MODALFRAME | DS_CENTER | WS_MINIMIZEBOX | WS_POPUP | WS_CAPTION | WS_SYSMENU
3535
EXSTYLE WS_EX_ACCEPTFILES
36-
CAPTION "Rufus 4.7.2214"
36+
CAPTION "Rufus 4.7.2215"
3737
FONT 9, "Segoe UI Symbol", 400, 0, 0x0
3838
BEGIN
3939
LTEXT "Drive Properties",IDS_DRIVE_PROPERTIES_TXT,8,6,53,12,NOT WS_GROUP
@@ -399,8 +399,8 @@ END
399399
//
400400

401401
VS_VERSION_INFO VERSIONINFO
402-
FILEVERSION 4,7,2214,0
403-
PRODUCTVERSION 4,7,2214,0
402+
FILEVERSION 4,7,2215,0
403+
PRODUCTVERSION 4,7,2215,0
404404
FILEFLAGSMASK 0x3fL
405405
#ifdef _DEBUG
406406
FILEFLAGS 0x1L
@@ -418,13 +418,13 @@ BEGIN
418418
VALUE "Comments", "https://rufus.ie"
419419
VALUE "CompanyName", "Akeo Consulting"
420420
VALUE "FileDescription", "Rufus"
421-
VALUE "FileVersion", "4.7.2214"
421+
VALUE "FileVersion", "4.7.2215"
422422
VALUE "InternalName", "Rufus"
423423
VALUE "LegalCopyright", "� 2011-2024 Pete Batard (GPL v3)"
424424
VALUE "LegalTrademarks", "https://www.gnu.org/licenses/gpl-3.0.html"
425425
VALUE "OriginalFilename", "rufus-4.7.exe"
426426
VALUE "ProductName", "Rufus"
427-
VALUE "ProductVersion", "4.7.2214"
427+
VALUE "ProductVersion", "4.7.2215"
428428
END
429429
END
430430
BLOCK "VarFileInfo"

src/syslinux/libfat/dumpdir.c

+14-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* ----------------------------------------------------------------------- *
22
*
3-
* Copyright 2019 Pete Batard <pete@akeo.ie>
3+
* Copyright 2019-2024 Pete Batard <pete@akeo.ie>
44
*
55
* This program is free software; you can redistribute it and/or modify
66
* it under the terms of the GNU General Public License as published by
@@ -19,6 +19,10 @@
1919
#include <string.h>
2020
#include "libfatint.h"
2121

22+
#ifndef ARRAYSIZE
23+
#define ARRAYSIZE(a) (sizeof(a) / sizeof(*(a)))
24+
#endif
25+
2226
static struct fat_dirent* get_next_dirent(struct libfat_filesystem *fs,
2327
libfat_sector_t *sector, int *offset)
2428
{
@@ -41,12 +45,12 @@ static struct fat_dirent* get_next_dirent(struct libfat_filesystem *fs,
4145
static void fill_utf16(wchar_t *name, unsigned char *entry)
4246
{
4347
int i;
44-
for (i=0; i<5; i++)
45-
name[i] = read16((le16_t*)&entry[1 + 2*i]);
46-
for (i=5; i<11; i++)
47-
name[i] = read16((le16_t*)&entry[4 + 2*i]);
48-
for (i=11; i<12; i++)
49-
name[i] = read16((le16_t*)&entry[6 + 2*i]);
48+
for (i = 0; i < 5; i++)
49+
name[i] = read16((le16_t*)&entry[1 + 2 * i]);
50+
for (i = 5; i < 11; i++)
51+
name[i] = read16((le16_t*)&entry[4 + 2 * i]);
52+
for (i = 11; i < 13; i++)
53+
name[i] = read16((le16_t*)&entry[6 + 2 * i]);
5054
}
5155

5256
int libfat_dumpdir(struct libfat_filesystem *fs, libfat_dirpos_t *dp,
@@ -94,11 +98,14 @@ int libfat_dumpdir(struct libfat_filesystem *fs, libfat_dirpos_t *dp,
9498
if ((j >= 0) && (i != j - 1))
9599
return -3;
96100
j = i;
101+
if (i > ARRAYSIZE(di->name) - 13)
102+
i = ARRAYSIZE(di->name) - 13;
97103
fill_utf16(&di->name[13 * i], dep->name);
98104
dep = get_next_dirent(fs, &dp->sector, &dp->offset);
99105
if (!dep)
100106
return -1;
101107
}
108+
di->name[ARRAYSIZE(di->name) - 1] = 0;
102109

103110
if (di->name[0] == 0) {
104111
for (i = 0, j = 0; i < 12; i++) {

0 commit comments

Comments
 (0)