Skip to content

Commit

Permalink
[iso] fix FAT filenames being truncated on image extraction
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
pbatard committed Dec 3, 2024
1 parent 8d1ed44 commit 3d5ab84
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 29 deletions.
29 changes: 12 additions & 17 deletions src/iso.c
Original file line number Diff line number Diff line change
Expand Up @@ -1758,8 +1758,8 @@ BOOL HasEfiImgBootLoaders(void)
int32_t dc, c;
struct libfat_filesystem *lf_fs = NULL;
struct libfat_direntry direntry;
char name[12] = { 0 }, bootloader_name[32];
int i, j, k;
char bootloader_name[16];
int i;

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

for (i = 0; i < ARRAYSIZE(efi_archname); i++) {
static_sprintf(bootloader_name, "boot%s.efi", efi_archname[i]);
// TODO: bootriscv64.efi and bootloongarch64.efi need LFN support
if (strlen(bootloader_name) > 12)
continue;
for (j = 0, k = 0; bootloader_name[j] != 0; j++) {
if (bootloader_name[j] == '.') {
while (k < 8)
name[k++] = ' ';
} else {
name[k++] = toupper(bootloader_name[j]);
}
}
c = libfat_searchdir(lf_fs, dc, name, &direntry);
for (i = 1; i < ARRAYSIZE(efi_archname); i++) {
// We consider it unlikely that any bootri#####.efi or bootlo#####.efi files
// in the /efi/boot/ subdirectory will be anything but 'bootriscv64.efi' and
// 'bootloongarch64.efi', so we'll use the ~1 LFN shortened names for them.
static_sprintf(bootloader_name, "BOOT%c%c%c%cEFI", efi_archname[i][0], efi_archname[i][1],
strlen(efi_archname[i]) > 4 ? '~' : efi_archname[i][2],
strlen(efi_archname[i]) > 4 ? '1' : (strlen(efi_archname[i]) > 3 ? efi_archname[i][3] : ' '));
safe_strtoupper(bootloader_name);
c = libfat_searchdir(lf_fs, dc, bootloader_name, &direntry);
if (c > 0) {
if (!ret)
uprintf(" Detected EFI bootloader(s) (from '%s'):", img_report.efi_img_path);
uprintf(" ● '%s'", bootloader_name);
uprintf(" ● 'boot%s.efi'", efi_archname[i]);
ret = TRUE;
}
}
Expand Down
1 change: 1 addition & 0 deletions src/rufus.h
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ static __inline void safe_strcp(char* dst, const size_t dst_max, const char* src
#define safe_vsnprintf vsnprintf
#endif
#define safe_strtolower(str) do { if (str != NULL) CharLowerA(str); } while(0)
#define safe_strtoupper(str) do { if (str != NULL) CharUpperA(str); } while(0)
static __inline void static_repchr(char* p, char s, char r) {
if (p != NULL) while (*p != 0) { if (*p == s) *p = r; p++; }
}
Expand Down
10 changes: 5 additions & 5 deletions src/rufus.rc
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL
IDD_DIALOG DIALOGEX 12, 12, 232, 326
STYLE DS_SETFONT | DS_MODALFRAME | DS_CENTER | WS_MINIMIZEBOX | WS_POPUP | WS_CAPTION | WS_SYSMENU
EXSTYLE WS_EX_ACCEPTFILES
CAPTION "Rufus 4.7.2214"
CAPTION "Rufus 4.7.2215"
FONT 9, "Segoe UI Symbol", 400, 0, 0x0
BEGIN
LTEXT "Drive Properties",IDS_DRIVE_PROPERTIES_TXT,8,6,53,12,NOT WS_GROUP
Expand Down Expand Up @@ -399,8 +399,8 @@ END
//

VS_VERSION_INFO VERSIONINFO
FILEVERSION 4,7,2214,0
PRODUCTVERSION 4,7,2214,0
FILEVERSION 4,7,2215,0
PRODUCTVERSION 4,7,2215,0
FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
FILEFLAGS 0x1L
Expand All @@ -418,13 +418,13 @@ BEGIN
VALUE "Comments", "https://rufus.ie"
VALUE "CompanyName", "Akeo Consulting"
VALUE "FileDescription", "Rufus"
VALUE "FileVersion", "4.7.2214"
VALUE "FileVersion", "4.7.2215"
VALUE "InternalName", "Rufus"
VALUE "LegalCopyright", "� 2011-2024 Pete Batard (GPL v3)"
VALUE "LegalTrademarks", "https://www.gnu.org/licenses/gpl-3.0.html"
VALUE "OriginalFilename", "rufus-4.7.exe"
VALUE "ProductName", "Rufus"
VALUE "ProductVersion", "4.7.2214"
VALUE "ProductVersion", "4.7.2215"
END
END
BLOCK "VarFileInfo"
Expand Down
21 changes: 14 additions & 7 deletions src/syslinux/libfat/dumpdir.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* ----------------------------------------------------------------------- *
*
* Copyright 2019 Pete Batard <[email protected]>
* Copyright 2019-2024 Pete Batard <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand All @@ -19,6 +19,10 @@
#include <string.h>
#include "libfatint.h"

#ifndef ARRAYSIZE
#define ARRAYSIZE(a) (sizeof(a) / sizeof(*(a)))
#endif

static struct fat_dirent* get_next_dirent(struct libfat_filesystem *fs,
libfat_sector_t *sector, int *offset)
{
Expand All @@ -41,12 +45,12 @@ static struct fat_dirent* get_next_dirent(struct libfat_filesystem *fs,
static void fill_utf16(wchar_t *name, unsigned char *entry)
{
int i;
for (i=0; i<5; i++)
name[i] = read16((le16_t*)&entry[1 + 2*i]);
for (i=5; i<11; i++)
name[i] = read16((le16_t*)&entry[4 + 2*i]);
for (i=11; i<12; i++)
name[i] = read16((le16_t*)&entry[6 + 2*i]);
for (i = 0; i < 5; i++)
name[i] = read16((le16_t*)&entry[1 + 2 * i]);
for (i = 5; i < 11; i++)
name[i] = read16((le16_t*)&entry[4 + 2 * i]);
for (i = 11; i < 13; i++)
name[i] = read16((le16_t*)&entry[6 + 2 * i]);
}

int libfat_dumpdir(struct libfat_filesystem *fs, libfat_dirpos_t *dp,
Expand Down Expand Up @@ -94,11 +98,14 @@ int libfat_dumpdir(struct libfat_filesystem *fs, libfat_dirpos_t *dp,
if ((j >= 0) && (i != j - 1))
return -3;
j = i;
if (i > ARRAYSIZE(di->name) - 13)
i = ARRAYSIZE(di->name) - 13;
fill_utf16(&di->name[13 * i], dep->name);
dep = get_next_dirent(fs, &dp->sector, &dp->offset);
if (!dep)
return -1;
}
di->name[ARRAYSIZE(di->name) - 1] = 0;

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

0 comments on commit 3d5ab84

Please sign in to comment.