PHAR internal corruption (crc32 mismatch) during process fork PHAR internal corruption (crc32 mismatch) during process fork php php

PHAR internal corruption (crc32 mismatch) during process fork


PHP Phar extension internally opens a Phar file and uses seek/tell/read operations on that descriptor to read the required files from the archive. Because forked processes all use the same descriptor and therefore also share the current file position pointer, then there is a race condition between these operations.

This problem is easily reproducible and happens with or without compression, but compression makes it more likely.

I'm not sure if this is actually a bug, because it is not easy to fix from PHP side and the same kind of problem likely exists for any PHP function, which have an open file descriptor in the background. It's more a problem of the documentation, which does not clearly state, that all the operations on the same Phar file share the same file descriptor in the background, even if it is not obvious from the PHP code.

The fix is to make sure you do not access the Phar before fork() or use some kind of locking mechanism when accessing the same Phar archive from different processes created by fork().


Seems like a PHP issue, report as a bug at https://bugs.php.net/ with steps to reproduce.