zziplib icon indicating copy to clipboard operation
zziplib copied to clipboard

Incorrect check for file descriptor validity can cause files to fail to open

Open amaurea opened this issue 6 years ago • 0 comments

Line 191 in file.c checks whether a file descriptor is valid, like this:

if (! dir->fd || dir->fd == -1)

This treats a file descriptor of 0 as a failure, but 0 is a fully valid file descriptor that can be returned from open. This caused mysterious problems opening files for me yesterday, so it's not just a theoretical issue. Usually a file descriptor of 0 is not encountered because it's taken up by standard input, so I guess that's why this has gone unnoticed, but on the supercomputer I ran this on (with intel compiler 19.0 and intel-mpi 2019.1), 0 was only reserved (presumably for standard input) on the root mpi task. For the others 0 was unallocated, and ended up being returned by open in zzip, causing file opens to fail for all mpi tasks except the root task.

Changing the line to

if(dir->fd == -1)

fixed the problem. I did not notice any side effects.

amaurea avatar Dec 14 '18 16:12 amaurea