Bug #81396 [NEW]: phar:// file fflush breaks file write

From: Date: Sun, 29 Aug 2021 11:03:37 +0000
Subject: Bug #81396 [NEW]: phar:// file fflush breaks file write
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-236154@lists.php.net to get a copy of this message
From: dixyes at gmail dot com Operating system: irrelative PHP version: 8.0.10 Package: PHAR related Bug Type: Bug Bug description:phar:// file fflush breaks file write Description: ------------ fflush file make strange result in phar files. this occurs on PHP 7.4 also, tested in windows and linux use php -n -dphar.readonly=0 test.php to test Test script: --------------- <?php // make up the phar $phar = new \Phar(__DIR__ . DIRECTORY_SEPARATOR . 'test.phar'); $phar->addEmptyDir('dir'); // may be irrelative $phar->stopBuffering(); //$phar_uri = __DIR__ . DIRECTORY_SEPARATOR . 'file'; $phar_uri = 'phar://' . __DIR__ . DIRECTORY_SEPARATOR . 'test.phar' . DIRECTORY_SEPARATOR . 'dir/file'; // make a file $f = fopen($phar_uri, 'w+'); fwrite($f, 'this is content '); fflush($f); // comment out this, things will be ok fwrite($f, "of file.\n"); fclose($f); // read it $f = fopen($phar_uri, 'r'); $content = fread($f, 4096); if ($content !== "this is content of file.\n") { throw new Exception("bad file context: $content vs 'this is content of file.\n'"); } else { echo "OK\n"; } Expected result: ---------------- OK Actual result: -------------- bad file context with strange things -- Edit bug report at https://bugs.php.net/bug.php?id=81396&edit=1 -- Fix committed: https://bugs.php.net/fix.php?id=81396&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=81396&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=81396&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=81396&r=needscript Try newer version: https://bugs.php.net/fix.php?id=81396&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=81396&r=support Expected behavior: https://bugs.php.net/fix.php?id=81396&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=81396&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=81396&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=81396&r=globals PHP version support discontinued: https://bugs.php.net/fix.php?id=81396&r=phptooold Daylight Savings: https://bugs.php.net/fix.php?id=81396&r=dst IIS Stability: https://bugs.php.net/fix.php?id=81396&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=81396&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=81396&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=81396&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=81396&r=mysqlcfg

« previous php.bugs (#236154) next »