From 3be85fe7ed694737ded136a2b43c105026b593d7 Mon Sep 17 00:00:00 2001 From: Jon Daniel Date: Tue, 1 Aug 2023 18:31:54 +0200 Subject: [PATCH] fix TAR not loading --- CMakeLists.txt | 9 +++++---- src/physfs_archiver_tar.c | 32 ++++++++++++++------------------ src/physfs_internal.h | 8 ++++---- src/physfs_tar.h | 2 +- 4 files changed, 24 insertions(+), 27 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index aedafd1f..e366814e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -126,15 +126,16 @@ if(NOT PHYSFS_ARCHIVE_WAD) add_definitions(-DPHYSFS_SUPPORTS_WAD=0) endif() +option(PHYSFS_ARCHIVE_TAR "Enable POSIX TAR / Chasm: The Rift [Demo] Remastered csm.bin support" TRUE) +if(NOT PHYSFS_ARCHIVE_TAR) + add_definitions(-DPHYSFS_SUPPORTS_TAR=0) +endif() + option(PHYSFS_ARCHIVE_CSM "Enable Chasm: The Rift CSM.BIN support" TRUE) if(NOT PHYSFS_ARCHIVE_CSM) add_definitions(-DPHYSFS_SUPPORTS_CSM=0) endif() -option(PHYSFS_ARCHIVE_TAR "Enable POSIX TAR / Chasm: The Rift [Demo] Remastered csm.bin support" TRUE) -if(NOT PHYSFS_ARCHIVE_TAR) - add_definitions(-DPHYSFS_SUPPORTS_TAR=0) -endif() option(PHYSFS_ARCHIVE_HOG "Enable Descent I/II HOG support" TRUE) if(NOT PHYSFS_ARCHIVE_HOG) diff --git a/src/physfs_archiver_tar.c b/src/physfs_archiver_tar.c index 03dcab68..ac8f40c1 100644 --- a/src/physfs_archiver_tar.c +++ b/src/physfs_archiver_tar.c @@ -12,21 +12,18 @@ #if PHYSFS_SUPPORTS_TAR #include "physfs_tar.h" -static bool TAR_loadEntries(PHYSFS_Io *io, void *arc) +static int TAR_loadEntries(PHYSFS_Io *io, void *arc) { - union block zero_block; - union block current_block; + union block zero_block = { 0 }; + union block current_block = { 0 }; PHYSFS_uint64 count = 0; bool long_name = false; - memset(zero_block.buffer, 0, sizeof(BLOCKSIZE)); - memset(current_block.buffer, 0, sizeof(BLOCKSIZE)); - /* read header block until zero-only terminated block */ - for(; __PHYSFS_readAll(io, current_block.buffer, BLOCKSIZE); count++) + for(; __PHYSFS_readAll(io, current_block.buffer, BLOCKSIZE) != 0; count++) { if( memcmp(current_block.buffer, zero_block.buffer, BLOCKSIZE) == 0 ) - return true; + return 1; /* verify magic */ switch(TAR_magic(¤t_block)) @@ -49,35 +46,34 @@ static bool TAR_loadEntries(PHYSFS_Io *io, void *arc) } } - return false; + return 0; } static void *TAR_openArchive(PHYSFS_Io *io, const char *name, int forWriting, int *claimed) { void *unpkarc = NULL; - union block first; - enum archive_format format; + char buf[BLOCKSIZE] = { '\0' }; assert(io != NULL); /* shouldn't ever happen. */ BAIL_IF(forWriting, PHYSFS_ERR_READ_ONLY, NULL); + BAIL_IF_ERRPASS(!__PHYSFS_readAll(io, buf, sizeof (buf)), NULL); + if ((memcmp(&buf[TMAGOFF], TMAGIC, TMAGLEN - 1) != 0) != 0) + BAIL(PHYSFS_ERR_UNSUPPORTED, NULL); - BAIL_IF_ERRPASS(!__PHYSFS_readAll(io, first.buffer, BLOCKSIZE), NULL); - format = TAR_magic(&first); - io->seek(io, 0); - *claimed = format == DEFAULT_FORMAT ? 0 : 1; + *claimed = 1; - unpkarc = UNPK_openArchive(io, 0, 1); + BAIL_IF_ERRPASS(!io->seek(io, 0), 0); + unpkarc = UNPK_openArchive(io, 1, 0); BAIL_IF_ERRPASS(!unpkarc, NULL); - if (!TAR_loadEntries(io, unpkarc)) + if (TAR_loadEntries(io, unpkarc) == 0) { UNPK_abandonArchive(unpkarc); return NULL; } /* if */ - return unpkarc; } /* TAR_openArchive */ diff --git a/src/physfs_internal.h b/src/physfs_internal.h index beff35d2..df1f5e50 100644 --- a/src/physfs_internal.h +++ b/src/physfs_internal.h @@ -88,8 +88,8 @@ extern const PHYSFS_Archiver __PHYSFS_Archiver_QPAK; extern const PHYSFS_Archiver __PHYSFS_Archiver_HOG; extern const PHYSFS_Archiver __PHYSFS_Archiver_MVL; extern const PHYSFS_Archiver __PHYSFS_Archiver_WAD; -extern const PHYSFS_Archiver __PHYSFS_Archiver_CSM; extern const PHYSFS_Archiver __PHYSFS_Archiver_TAR; +extern const PHYSFS_Archiver __PHYSFS_Archiver_CSM; extern const PHYSFS_Archiver __PHYSFS_Archiver_SLB; extern const PHYSFS_Archiver __PHYSFS_Archiver_ISO9660; extern const PHYSFS_Archiver __PHYSFS_Archiver_VDF; @@ -202,12 +202,12 @@ void __PHYSFS_smallFree(void *ptr); #ifndef PHYSFS_SUPPORTS_WAD #define PHYSFS_SUPPORTS_WAD PHYSFS_SUPPORTS_DEFAULT #endif -#ifndef PHYSFS_SUPPORTS_CSM -#define PHYSFS_SUPPORTS_CSM PHYSFS_SUPPORTS_DEFAULT -#endif #ifndef PHYSFS_SUPPORTS_TAR #define PHYSFS_SUPPORTS_TAR PHYSFS_SUPPORTS_DEFAULT #endif +#ifndef PHYSFS_SUPPORTS_CSM +#define PHYSFS_SUPPORTS_CSM PHYSFS_SUPPORTS_DEFAULT +#endif #ifndef PHYSFS_SUPPORTS_QPAK #define PHYSFS_SUPPORTS_QPAK PHYSFS_SUPPORTS_DEFAULT #endif diff --git a/src/physfs_tar.h b/src/physfs_tar.h index 28da558c..dbc0092f 100644 --- a/src/physfs_tar.h +++ b/src/physfs_tar.h @@ -26,7 +26,7 @@ #define TMAGIC "ustar" /* ustar and a null */ #define OLDGNU_MAGIC "ustar " /* 7 chars and a null */ #define TMAGLEN 6 - +#define TMAGOFF 257 #define TVERSION "00" /* 00 and no null */ #define TVERSLEN 2