[physfs] Bug - "file not found" if path is substring of another file

Paul napalminc at gmail.com
Tue Sep 4 19:22:47 EDT 2012

Good day,

I believe I might have found a bug in PhysFS in checking for the
existance of a file whose name it is a substring of another file. In
the following code, I believe that PHYSFS_exists() should return

$ cat main.c
#include <physfs.h>

int main(int argc, char *argv[])
        PHYSFS_addToSearchPath("bar.zip", 0);
        return PHYSFS_exists("foo");

$ cat build.sh
touch foo
touch foo.a
touch xyz
zip bar.zip foo foo.a xyz
gcc main.c -o main -lphysfs
if [ "$?" -eq "0" ]; then
        echo FAILURE
        echo SUCCESS

I have only looked at the ZIP archiver, but this can be fixed to
return the correct value if in zip_find_entry(), when a substring is
matched, "hi" is always modified, "lo" never.

-else if (thispath[pathlen] > '/')
     hi = middle - 1;
-    lo = middle + 1;

I am not sure how this change plays out with the isDir subtleties, and
this change might cause problems with that. I have not thoroughly
tested for anything of the sort.

Also, I have not investigated the other archiver modules to see if
they are similarly affected. It might be worth a check.

Paul Merrill

More information about the physfs mailing list