icculus / physfs

A portable, flexible file i/o abstraction.
https://icculus.org/physfs/
zlib License
560 stars 98 forks source link

Problem with root directories #4

Closed ghost closed 2 years ago

ghost commented 3 years ago

I'm calling PHYSFS_stat() on a directory contained in the root, and with a single ZIP mounted and a "root directory" set to "data"

In function verifyPath(), the "prepend the root directory, if any" section, fname[] is being set to "dat/dir" rather than "data/dir". The issue seems to be an off-by-one, when prepending the root directory.

Old code:

if (h->root)
{
    const int isempty = (*fname == '\0');
    fname -= h->rootlen - 1;
    strcpy(fname, h->root);
    if (!isempty)
        fname[h->rootlen - 2] = '/';
    *_fname = fname;
} /* if */

Modified code:

if (h->root)
{
    const int isempty = (*fname == '\0');
    fname -= h->rootlen;
    strcpy(fname, h->root);
    if (!isempty)
        fname[h->rootlen - 1] = '/';
    *_fname = fname;
} /* if */

This seems to fix the problem, but I'm not sure if it could introduce problems elsewhere.

icculus commented 2 years ago

Ah, this has been working for me because I did PHYSFS_setRoot("/assets") and sanitizePlatformIndependentPath removes the '/' but we keep the length before sanitizing.

icculus commented 2 years ago

This was actually messier than expected, but it should be fixed now.