From 7355ab81763a3d6a04ac11660e6a16d58838d187 Mon Sep 17 00:00:00 2001 From: "Christoph M. Becker" Date: Tue, 14 Jul 2020 17:04:24 +0200 Subject: [PATCH 1/2] Fix #79797: Use of freed hash key in the phar_parse_zipfile function We must not use heap memory after we freed it. --- ext/phar/tests/bug79797.phar | Bin 0 -> 274 bytes ext/phar/tests/bug79797.phpt | 14 ++++++++++++++ ext/phar/zip.c | 2 +- 3 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 ext/phar/tests/bug79797.phar create mode 100644 ext/phar/tests/bug79797.phpt diff --git a/ext/phar/tests/bug79797.phar b/ext/phar/tests/bug79797.phar new file mode 100644 index 0000000000000000000000000000000000000000..21d43d9eeb61ccbd1fd0d14ccee19d2896656a8a GIT binary patch literal 274 zcmWIWW@cdkgT~OA?qwg{S^xiMU;tqj1|fz-Ajm7_V+hxFY}v*LQOCd#;LXScV`I|= zlY`LM%>cP{a`kh|w(oaso)PBLI@CGamo| literal 0 HcmV?d00001 diff --git a/ext/phar/tests/bug79797.phpt b/ext/phar/tests/bug79797.phpt new file mode 100644 index 00000000000..761e5379e00 --- /dev/null +++ b/ext/phar/tests/bug79797.phpt @@ -0,0 +1,14 @@ +--TEST-- +Bug #79797 (Use of freed hash key in the phar_parse_zipfile function) +--SKIPIF-- + +--INI-- +phar.cache_list={PWD}/bug79797.phar +--FILE-- + +--EXPECT-- +done diff --git a/ext/phar/zip.c b/ext/phar/zip.c index d615e8addaf..50c5d69e9be 100644 --- a/ext/phar/zip.c +++ b/ext/phar/zip.c @@ -703,7 +703,7 @@ foundit: efree(actual_alias); } - zend_hash_str_add_ptr(&(PHAR_G(phar_alias_map)), actual_alias, mydata->alias_len, mydata); + zend_hash_str_add_ptr(&(PHAR_G(phar_alias_map)), mydata->alias, mydata->alias_len, mydata); } else { phar_archive_data *fd_ptr; From ff577b04c0d250473a0ef46f8e332960fec3ca2c Mon Sep 17 00:00:00 2001 From: "Christoph M. Becker" Date: Tue, 21 Jul 2020 11:07:43 +0200 Subject: [PATCH 2/2] Fix #79877: getimagesize function silently truncates after a null byte We have to check for NUL bytes if `getimagesize()` has been called. --- ext/standard/image.c | 5 +++++ ext/standard/tests/image/bug79877.phpt | 9 +++++++++ 2 files changed, 14 insertions(+) create mode 100644 ext/standard/tests/image/bug79877.phpt diff --git a/ext/standard/image.c b/ext/standard/image.c index c634727ea35..4e63411904f 100644 --- a/ext/standard/image.c +++ b/ext/standard/image.c @@ -1478,6 +1478,11 @@ static void php_getimagesize_from_any(INTERNAL_FUNCTION_PARAMETERS, int mode) { Z_PARAM_ZVAL_DEREF(info) ZEND_PARSE_PARAMETERS_END(); + if (mode == FROM_PATH && CHECK_NULL_PATH(input, input_len)) { + php_error_docref(NULL, E_WARNING, "Invalid path"); + return; + } + if (argc == 2) { zval_ptr_dtor(info); array_init(info); diff --git a/ext/standard/tests/image/bug79877.phpt b/ext/standard/tests/image/bug79877.phpt new file mode 100644 index 00000000000..92e93e59e53 --- /dev/null +++ b/ext/standard/tests/image/bug79877.phpt @@ -0,0 +1,9 @@ +--TEST-- +Bug #79877 (getimagesize function silently truncates after a null byte) +--FILE-- + +--EXPECTF-- +Warning: getimagesize(): Invalid path in %s on line %d +NULL