summaryrefslogtreecommitdiffstats
path: root/7cf5099820367e314d2bb34a289e376e248539c6.patch
blob: d90bfd2f5df37011981006a1e7d232587c58976a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
From 7cf5099820367e314d2bb34a289e376e248539c6 Mon Sep 17 00:00:00 2001
From: Remi Collet <remi@remirepo.net>
Date: Tue, 23 Jul 2019 16:14:57 +0200
Subject: [PATCH] sync changes from php-src

---
 php74/php_zip.c    | 44 ++++++++++++++++++++++++++++----------------
 php74/php_zip.h    |  4 ----
 php74/zip_stream.c | 10 +++++-----
 3 files changed, 33 insertions(+), 25 deletions(-)

diff --git a/php74/php_zip.c b/php74/php_zip.c
index df3eade..fabd30e 100644
--- a/php74/php_zip.c
+++ b/php74/php_zip.c
@@ -677,19 +677,6 @@ int php_zip_pcre(zend_string *regexp, char *path, int path_len, zval *return_val
 				break;
 			}
 
-			snprintf(fullpath, MAXPATHLEN, "%s%c%s", path, DEFAULT_SLASH, ZSTR_VAL(namelist[i]));
-
-			if (0 != VCWD_STAT(fullpath, &s)) {
-				php_error_docref(NULL, E_WARNING, "Cannot read <%s>", fullpath);
-				zend_string_release_ex(namelist[i], 0);
-				continue;
-			}
-
-			if (S_IFDIR == (s.st_mode & S_IFMT)) {
-				zend_string_release_ex(namelist[i], 0);
-				continue;
-			}
-
 			match_data = php_pcre_create_match_data(capture_count, re);
 			if (!match_data) {
 				/* Allocation failed, but can proceed to the next pattern. */
@@ -704,6 +691,19 @@ int php_zip_pcre(zend_string *regexp, char *path, int path_len, zval *return_val
 				continue;
 			}
 
+			snprintf(fullpath, MAXPATHLEN, "%s%c%s", path, DEFAULT_SLASH, ZSTR_VAL(namelist[i]));
+
+			if (0 != VCWD_STAT(fullpath, &s)) {
+				php_error_docref(NULL, E_WARNING, "Cannot read <%s>", fullpath);
+				zend_string_release_ex(namelist[i], 0);
+				continue;
+			}
+
+			if (S_IFDIR == (s.st_mode & S_IFMT)) {
+				zend_string_release_ex(namelist[i], 0);
+				continue;
+			}
+
 			add_next_index_string(return_value, fullpath);
 			zend_string_release_ex(namelist[i], 0);
 		}
@@ -873,7 +873,11 @@ static zval *php_zip_get_property_ptr_ptr(zval *object, zval *member, int type,
 	zip_prop_handler *hnd = NULL;
 
 	if (Z_TYPE_P(member) != IS_STRING) {
-		ZVAL_STR(&tmp_member, zval_get_string_func(member));
+		zend_string *str = zval_try_get_string_func(member);
+		if (UNEXPECTED(!str)) {
+			return NULL;
+		}
+		ZVAL_STR(&tmp_member, str);
 		member = &tmp_member;
 		cache_slot = NULL;
 	}
@@ -904,7 +908,11 @@ static zval *php_zip_read_property(zval *object, zval *member, int type, void **
 	zip_prop_handler *hnd = NULL;
 
 	if (Z_TYPE_P(member) != IS_STRING) {
-		ZVAL_STR(&tmp_member, zval_get_string_func(member));
+		zend_string *str = zval_try_get_string_func(member);
+		if (UNEXPECTED(!str)) {
+			return &EG(uninitialized_zval);
+		}
+		ZVAL_STR(&tmp_member, str);
 		member = &tmp_member;
 		cache_slot = NULL;
 	}
@@ -940,7 +948,11 @@ static int php_zip_has_property(zval *object, zval *member, int type, void **cac
 	int retval = 0;
 
 	if (Z_TYPE_P(member) != IS_STRING) {
-		ZVAL_STR(&tmp_member, zval_get_string_func(member));
+		zend_string *str = zval_try_get_string_func(member);
+		if (UNEXPECTED(!str)) {
+			return 0;
+		}
+		ZVAL_STR(&tmp_member, str);
 		member = &tmp_member;
 		cache_slot = NULL;
 	}
diff --git a/php74/php_zip.h b/php74/php_zip.h
index 191be54..0ac9189 100644
--- a/php74/php_zip.h
+++ b/php74/php_zip.h
@@ -27,11 +27,7 @@ extern zend_module_entry zip_module_entry;
 #include "TSRM.h"
 #endif
 
-#if defined(HAVE_LIBZIP)
 #include <zip.h>
-#else
-#include "lib/zip.h"
-#endif
 
 #ifndef ZIP_OVERWRITE
 #define ZIP_OVERWRITE ZIP_TRUNCATE
diff --git a/php74/zip_stream.c b/php74/zip_stream.c
index f24a91f..bce62f5 100644
--- a/php74/zip_stream.c
+++ b/php74/zip_stream.c
@@ -45,7 +45,7 @@ struct php_zip_stream_data_t {
 
 
 /* {{{ php_zip_ops_read */
-static size_t php_zip_ops_read(php_stream *stream, char *buf, size_t count)
+static ssize_t php_zip_ops_read(php_stream *stream, char *buf, size_t count)
 {
 	ssize_t n = 0;
 	STREAM_DATA_FROM_STREAM();
@@ -65,7 +65,7 @@ static size_t php_zip_ops_read(php_stream *stream, char *buf, size_t count)
 			php_error_docref(NULL, E_WARNING, "Zip stream error: %s", zip_error_strerror(err));
 			zip_error_fini(err);
 #endif
-			return 0;
+			return -1;
 		}
 		/* cast count to signed value to avoid possibly negative n
 		 * being cast to unsigned value */
@@ -75,15 +75,15 @@ static size_t php_zip_ops_read(php_stream *stream, char *buf, size_t count)
 			self->cursor += n;
 		}
 	}
-	return (n < 1 ? 0 : (size_t)n);
+	return n;
 }
 /* }}} */
 
 /* {{{ php_zip_ops_write */
-static size_t php_zip_ops_write(php_stream *stream, const char *buf, size_t count)
+static ssize_t php_zip_ops_write(php_stream *stream, const char *buf, size_t count)
 {
 	if (!stream) {
-		return 0;
+		return -1;
 	}
 
 	return count;