Skip to content

Commit

Permalink
FS: Remove last traces of iscompressed in vfs_zip. (#891)
Browse files Browse the repository at this point in the history
Most of the uses had already been removed, but remained in the case of a
seek. As cmodel now uses seeks during checksum, this uncovered the last
use case.

As iscompressed wasn't set, the vfsz->defer remained NULL, and thus
reading of pk3 content after a seek failed.

The origin of this file is FTE, ideally a newer version is imported but
the rest of the FTE VFS guts has evolved since last import.

fixes #885
  • Loading branch information
dsvensson committed Jan 31, 2024
1 parent fe56fee commit 16102c1
Showing 1 changed file with 28 additions and 59 deletions.
87 changes: 28 additions & 59 deletions src/vfs_zip.c
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,6 @@ typedef struct {

//in case we're forced away.
zipfile_t *parent;
qbool iscompressed;
int pos;
int length; //try and optimise some things
int index;
Expand Down Expand Up @@ -181,23 +180,9 @@ static int VFSZIP_ReadBytes (struct vfsfile_s *file, void *buffer, int bytestore
if (vfsz->defer)
return VFS_READ(vfsz->defer, buffer, bytestoread, err);

// if (vfsz->iscompressed)
// {
VFSZIP_MakeActive(vfsz);
read = unzReadCurrentFile(vfsz->parent->handle, buffer, bytestoread);
// }
// else
// {
// VFS-FIXME This stuff seems to be only for optimisation,
// hence we can probably just go with unzReadCurrentFile
// if (vfsz->parent->currentfile != file)
// {
// unzCloseCurrentFile(vfsz->parent->handle);
// VFS_SEEK(vfsz->parent->raw, vfsz->pos+vfsz->startpos, SEEK_SET);
// vfsz->parent->currentfile = file;
// }
// read = VFS_READ(vfsz->parent->raw, buffer, bytestoread, err);
// }
VFSZIP_MakeActive(vfsz);
read = unzReadCurrentFile(vfsz->parent->handle, buffer, bytestoread);

if (err)
*err = ((read || bytestoread <= 0) ? VFSERR_NONE : VFSERR_EOF);

Expand All @@ -222,35 +207,32 @@ static int VFSZIP_Seek (struct vfsfile_s *file, unsigned long pos, int whence)
//This is *really* inefficient
if (vfsz->parent->currentfile == file)
{
if (vfsz->iscompressed)
{ //if they're going to seek on a file in a zip, let's just copy it out
char buffer[8192];
unsigned int chunk;
unsigned int i;
unsigned int length;

vfsz->defer = FS_OpenTemp();
if (vfsz->defer)
char buffer[8192];
unsigned int chunk;
unsigned int i;
unsigned int length;

vfsz->defer = FS_OpenTemp();
if (vfsz->defer)
{
unzCloseCurrentFile(vfsz->parent->handle);
vfsz->parent->currentfile = NULL; //make it not us

length = vfsz->length;
i = 0;
vfsz->pos = 0;
VFSZIP_MakeActive(vfsz);
while (1)
{
unzCloseCurrentFile(vfsz->parent->handle);
vfsz->parent->currentfile = NULL; //make it not us

length = vfsz->length;
i = 0;
vfsz->pos = 0;
VFSZIP_MakeActive(vfsz);
while (1)
{
chunk = length - i;
if (chunk > sizeof(buffer))
chunk = sizeof(buffer);
if (chunk == 0)
break;
unzReadCurrentFile(vfsz->parent->handle, buffer, chunk);
VFS_WRITE(vfsz->defer, buffer, chunk);

i += chunk;
}
chunk = length - i;
if (chunk > sizeof(buffer))
chunk = sizeof(buffer);
if (chunk == 0)
break;
unzReadCurrentFile(vfsz->parent->handle, buffer, chunk);
VFS_WRITE(vfsz->defer, buffer, chunk);

i += chunk;
}
}

Expand Down Expand Up @@ -327,19 +309,6 @@ static vfsfile_t *FSZIP_OpenVFS(void *handle, flocation_t *loc, char *mode)
if (loc->search)
vfsz->funcs.copyprotected = loc->search->copyprotected;

// VFS-FIXME:
// What is the point of is compressed etc

//unzLocateFileMy(vfsz->parent->handle, vfsz->index, vfsz->startpos);
//rawofs = unzGetCurrentFileUncompressedPos(zip->handle);
/*vfsz->iscompressed = 1; // rawofs<0;
if (!vfsz->iscompressed)
{
vfsz->startpos = rawofs;
VFS_SEEK(zip->raw, vfsz->startpos, SEEK_SET);
vfsz->parent->currentfile = (vfsfile_t*)vfsz;
}*/

zip->references++;

return (vfsfile_t*)vfsz;
Expand Down

0 comments on commit 16102c1

Please sign in to comment.