From 4a63955e22fc3f2379fe6493d2daa0b5b6effb9e Mon Sep 17 00:00:00 2001 From: Pete Batard Date: Mon, 16 Jan 2012 14:05:46 +0000 Subject: [PATCH] [iso9660] workaround for zero sized filename array and MSVC * use an union of iso711_t and char (same size), and and access the string starting at index 1 --- src/libcdio/cdio/iso9660.h | 17 +++++++++++++++-- src/libcdio/iso9660/iso9660.c | 4 ++-- src/libcdio/iso9660/iso9660_fs.c | 14 +++++++------- src/libcdio/iso9660/rock.c | 8 ++++---- src/rufus.rc | 12 ++++++------ 5 files changed, 34 insertions(+), 21 deletions(-) diff --git a/src/libcdio/cdio/iso9660.h b/src/libcdio/cdio/iso9660.h index df5be6b1..769a0d8f 100644 --- a/src/libcdio/cdio/iso9660.h +++ b/src/libcdio/cdio/iso9660.h @@ -233,6 +233,20 @@ typedef struct iso9660_stat_s iso9660_stat_t; #include +/*! MSVC compilers cannot handle a zero sized array in the middle of a struct, and + uct iso9660_dir_s is reused in the middle of iso9660_pvd_s, so instead of having + iso711_t filename_len; + char filename[]; + we use the fact that iso711_t and char are the same size and use an union. + The only gotcha is that the actual string payload starts at 1, not 0 +*/ +union iso9660_filename_u { + iso711_t len; + char str[1]; +} GNUC_PACKED; + +typedef union iso9660_filename_u iso9660_filename_t; + /*! \brief Format of an ISO-9660 directory record Section 9.1 of ECMA 119. @@ -273,8 +287,7 @@ struct iso9660_dir_s { the Extent described by this Directory Record is recorded. (9.1.9) */ - iso711_t filename_len; /*! number of bytes in filename field */ - char filename[EMPTY_ARRAY_SIZE]; + iso9660_filename_t filename; } GNUC_PACKED; /*! diff --git a/src/libcdio/iso9660/iso9660.c b/src/libcdio/iso9660/iso9660.c index 72a67677..75e1539c 100644 --- a/src/libcdio/iso9660/iso9660.c +++ b/src/libcdio/iso9660/iso9660.c @@ -771,10 +771,10 @@ iso9660_dir_add_entry_su(void *dir, idr->volume_sequence_number = to_723(1); - idr->filename_len = to_711(strlen(filename) + idr->filename.len = to_711(strlen(filename) ? strlen(filename) : 1); /* working hack! */ - memcpy(idr->filename, filename, from_711(idr->filename_len)); + memcpy(&idr->filename.str[1], filename, from_711(idr->filename.len)); memcpy(&dir8[offset] + su_offset, su_data, su_size); } diff --git a/src/libcdio/iso9660/iso9660_fs.c b/src/libcdio/iso9660/iso9660_fs.c index d7af6d71..c828ebdb 100644 --- a/src/libcdio/iso9660/iso9660_fs.c +++ b/src/libcdio/iso9660/iso9660_fs.c @@ -744,7 +744,7 @@ _iso9660_dir_to_statbuf (iso9660_dir_t *p_iso9660_dir, bool_3way_t b_xa, if (!dir_len) return NULL; - i_fname = from_711(p_iso9660_dir->filename_len); + i_fname = from_711(p_iso9660_dir->filename.len); /* .. string in statbuf is one longer than in p_iso9660_dir's listing '\1' */ stat_len = sizeof(iso9660_stat_t)+i_fname+2; @@ -789,9 +789,9 @@ _iso9660_dir_to_statbuf (iso9660_dir_t *p_iso9660_dir, bool_3way_t b_xa, } strncpy(p_stat->filename, rr_fname, i_rr_fname+1); } else { - if ('\0' == p_iso9660_dir->filename[0] && 1 == i_fname) + if ('\0' == p_iso9660_dir->filename.str[1] && 1 == i_fname) strncpy (p_stat->filename, ".", sizeof(".")); - else if ('\1' == p_iso9660_dir->filename[0] && 1 == i_fname) + else if ('\1' == p_iso9660_dir->filename.str[1] && 1 == i_fname) strncpy (p_stat->filename, "..", sizeof("..")); #ifdef HAVE_JOLIET else if (i_joliet_level) { @@ -809,7 +809,7 @@ _iso9660_dir_to_statbuf (iso9660_dir_t *p_iso9660_dir, bool_3way_t b_xa, } #endif /*HAVE_JOLIET*/ else { - strncpy (p_stat->filename, p_iso9660_dir->filename, i_fname); + strncpy (p_stat->filename, &p_iso9660_dir->filename.str[1], i_fname); } } } @@ -883,12 +883,12 @@ iso9660_dir_to_name (const iso9660_dir_t *iso9660_dir) /* (iso9660_dir->file_flags & ISO_DIRECTORY) */ - if (iso9660_dir->filename[0] == '\0') + if (iso9660_dir->filename.str[1] == '\0') return _strdup("."); - else if (iso9660_dir->filename[0] == '\1') + else if (iso9660_dir->filename.str[1] == '\1') return _strdup(".."); else { - return _strdup(iso9660_dir->filename); + return _strdup(&iso9660_dir->filename.str[1]); } } diff --git a/src/libcdio/iso9660/rock.c b/src/libcdio/iso9660/rock.c index b59d1e61..b61a4d95 100644 --- a/src/libcdio/iso9660/rock.c +++ b/src/libcdio/iso9660/rock.c @@ -121,7 +121,7 @@ realloc_symlink(/*in/out*/ iso9660_stat_t *p_stat, uint8_t i_grow) #define SETUP_ROCK_RIDGE(DE,CHR,LEN) \ { \ - LEN= sizeof(iso9660_dir_t) + DE->filename_len; \ + LEN= sizeof(iso9660_dir_t) + DE->filename.len; \ if(LEN & 1) LEN++; \ CHR = ((unsigned char *) DE) + LEN; \ LEN = *((unsigned char *) DE) - LEN; \ @@ -194,10 +194,10 @@ get_rock_ridge_filename(iso9660_dir_t * p_iso9660_dir, break; case SIG('C','E'): { - iso711_t i_fname = from_711(p_iso9660_dir->filename_len); - if ('\0' == p_iso9660_dir->filename[0] && 1 == i_fname) + iso711_t i_fname = from_711(p_iso9660_dir->filename.len); + if ('\0' == p_iso9660_dir->filename.str[1] && 1 == i_fname) break; - if ('\1' == p_iso9660_dir->filename[0] && 1 == i_fname) + if ('\1' == p_iso9660_dir->filename.str[1] && 1 == i_fname) break; } CHECK_CE; diff --git a/src/rufus.rc b/src/rufus.rc index 839a1877..13420ee1 100644 --- a/src/rufus.rc +++ b/src/rufus.rc @@ -33,7 +33,7 @@ LANGUAGE LANG_ENGLISH, SUBLANG_NEUTRAL IDD_DIALOG DIALOGEX 12, 12, 206, 278 STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU EXSTYLE WS_EX_APPWINDOW -CAPTION "Rufus v1.0.7.131" +CAPTION "Rufus v1.0.7.132" FONT 8, "MS Shell Dlg", 400, 0, 0x1 BEGIN DEFPUSHBUTTON "Start",IDC_START,94,236,50,14 @@ -70,7 +70,7 @@ BEGIN DEFPUSHBUTTON "OK",IDOK,231,175,50,14,WS_GROUP CONTROL "http://rufus.akeo.ie",IDC_ABOUT_RUFUS_URL, "SysLink",WS_TABSTOP,46,47,114,9 - LTEXT "Version 1.0.7 (Build 131)",IDC_STATIC,46,19,78,8 + LTEXT "Version 1.0.7 (Build 132)",IDC_STATIC,46,19,78,8 PUSHBUTTON "License...",IDC_ABOUT_LICENSE,46,175,50,14,WS_GROUP EDITTEXT IDC_ABOUT_COPYRIGHTS,46,107,235,63,ES_MULTILINE | ES_READONLY | WS_VSCROLL LTEXT "Report bugs or request enhancements at:",IDC_STATIC,46,66,187,8 @@ -208,8 +208,8 @@ END // VS_VERSION_INFO VERSIONINFO - FILEVERSION 1,0,7,131 - PRODUCTVERSION 1,0,7,131 + FILEVERSION 1,0,7,132 + PRODUCTVERSION 1,0,7,132 FILEFLAGSMASK 0x3fL #ifdef _DEBUG FILEFLAGS 0x1L @@ -226,13 +226,13 @@ BEGIN BEGIN VALUE "CompanyName", "akeo.ie" VALUE "FileDescription", "Rufus" - VALUE "FileVersion", "1.0.7.131" + VALUE "FileVersion", "1.0.7.132" VALUE "InternalName", "Rufus" VALUE "LegalCopyright", "© 2011 Pete Batard (GPL v3)" VALUE "LegalTrademarks", "http://www.gnu.org/copyleft/gpl.html" VALUE "OriginalFilename", "rufus.exe" VALUE "ProductName", "Rufus" - VALUE "ProductVersion", "1.0.7.131" + VALUE "ProductVersion", "1.0.7.132" END END BLOCK "VarFileInfo"