[php-src] master: phar: Fix file descriptor leak in phar_zip_flush() on failure.

From: Date: Tue, 21 Oct 2025 17:37:41 +0000
Subject: [php-src] master: phar: Fix file descriptor leak in phar_zip_flush() on failure.
Groups: php.cvs 
Request: Send a blank email to [email protected] to get a copy of this message
Author: Niels Dossche (nielsdos)
Date: 2025-10-21T19:36:08+02:00

Commit: https://github.com/php/php-src/commit/cc837614163084ce522b7c5a3cf241c388f38311
Raw diff: https://github.com/php/php-src/commit/cc837614163084ce522b7c5a3cf241c388f38311.diff

phar: Fix file descriptor leak in phar_zip_flush() on failure.

Closes GH-20228.

Changed paths:
  M  NEWS
  M  ext/phar/zip.c


Diff:

diff --git a/NEWS b/NEWS
index 020927bb5ff6..4345f86f98ec 100644
--- a/NEWS
+++ b/NEWS
@@ -56,6 +56,7 @@ PHP                                                                        NEWS
   . Fix potential buffer length truncation due to usage of type int instead
     of type size_t. (Girgias)
   . Fix memory leak when openssl polyfill returns garbage. (nielsdos)
+  . Fix file descriptor leak in phar_zip_flush() on failure. (nielsdos)
 
 - Random:
   . Fix Randomizer::__serialize() w.r.t. INDIRECTs. (nielsdos)
diff --git a/ext/phar/zip.c b/ext/phar/zip.c
index f1d0edd5bdff..63c56108ed98 100644
--- a/ext/phar/zip.c
+++ b/ext/phar/zip.c
@@ -1246,6 +1246,7 @@ int phar_zip_flush(phar_archive_data *phar, char *user_stub, zend_long len,
int
 			return EOF;
 		}
 		if (phar->alias_len != php_stream_write(entry.fp, phar->alias, phar->alias_len)) {
+			php_stream_close(entry.fp);
 			if (error) {
 				spprintf(error, 0, "unable to set alias in zip-based phar \"%s\"",
phar->fname);
 			}


Thread (1 message)

  • Niels Dossche
« previous php.cvs (#136494) next »