[php-src] PR #21803: phar: fix resource leaks on error paths (GH-21798)
| From: | iliaal | Date: | Sat, 18 Apr 2026 14:17:33 +0000 |
| Subject: | [php-src] PR #21803: phar: fix resource leaks on error paths (GH-21798) | ||
| Groups: | php.git-pulls | ||
| Request: | Send a blank email to git-pulls+get-35774@lists.php.net to get a copy of this message | ||
Pull Request: https://github.com/php/php-src/pull/21803
Author: iliaal
Three low-severity resource management fixes filed as php/php-src#21798.
**phar.c — cap OpenSSL signature_len before emalloc**
signature_len is a uint32_t read from the phar file without any upper
bound. A crafted phar could request a multi-gigabyte heap allocation on a 64-bit build. The 1 MiB
cap is generous for real RSA signatures (RSA-8192 produces 1024 bytes) while blocking the resource
exhaustion vector.
**phar_object.c — free is_temp_dir entry before .phar/* rejection in offsetGet**
phar_get_entry_info_dir with allow_dir=1 may return a heap-allocated
temporary directory entry (is_temp_dir=1). Three early-exit paths for
.phar/stub.php, .phar/alias.txt, and the generic .phar/*
prefix called RETURN_THROWS() before the is_temp_dir cleanup block,
leaking both the entry struct and its filename buffer. Moving the cleanup before the guards fixes
all three exit paths.
**phar_object.c — phar_entry_delref before goto finish in phar_add_file**
phar_get_or_create_entry_data_rw increments the entry reference count; the caller must
balance with phar_entry_delref. Two error paths in the content-write block jumped to
finish: via goto, bypassing the phar_entry_delref call. The
finish: label sits after the delref on the success path. Added
phar_entry_delref(data) before each goto finish in those branches.
Fixes #21798