com php-src: Fixed bug #7143 (finfo throws no tice for specific python file): NEWS ext/filein fo/libmagic/softmagic.c
| From: | Xinchen Hui | Date: | Mon, 25 Jan 2016 03:24:44 +0000 |
| Subject: | com php-src: Fixed bug #7143 (finfo throws no tice for specific python file): NEWS ext/filein fo/libmagic/softmagic.c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-90745@lists.php.net to get a copy of this message | ||
Commit: a458a4fdc1d73638f31b84f709eb97838760f17e
Author: Xinchen Hui <laruence@gmail.com> Mon, 25 Jan 2016 11:20:48 +0800
Parents: 848de651a2fb6687592bff79a425825676984c88
Branches: PHP-5.6
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=a458a4fdc1d73638f31b84f709eb97838760f17e
Log:
Fixed bug #7143 (finfo throws notice for specific python file)
There seems be a bug while it was changed from regexec to
preg_match_impl:
https://github.com/php/php-src/commit/46906925#diff-56e765972d18c84894ea061cfe58076aR1757
Bugs:
https://bugs.php.net/7143
Changed paths:
M NEWS
M ext/fileinfo/libmagic/softmagic.c
Diff:
diff --git a/NEWS b/NEWS
index d3c3af4..2dca96f 100644
--- a/NEWS
+++ b/NEWS
@@ -2,6 +2,9 @@ PHP NEWS
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
?? ??? 2016, PHP 5.6.19
+- Fileinfo:
+ . Fixed bug #71434 (finfo throws notice for specific python file). (Laruence)
+
04 Feb 2016, PHP 5.6..18
- Core:
diff --git a/ext/fileinfo/libmagic/softmagic.c b/ext/fileinfo/libmagic/softmagic.c
index 04bff50..d39d44b 100644
--- a/ext/fileinfo/libmagic/softmagic.c
+++ b/ext/fileinfo/libmagic/softmagic.c
@@ -2114,7 +2114,7 @@ magiccheck(struct magic_set *ms, struct magic *m)
haystack = estrndup(ms->search.s, ms->search.s_len);
/* match v = 0, no match v = 1 */
- php_pcre_match_impl(pce, haystack, ms->search.s_len, retval, subpats, 1, 1,
PREG_OFFSET_CAPTURE, 0 TSRMLS_CC);
+ php_pcre_match_impl(pce, haystack, ms->search.s_len, retval, subpats, 0, 1,
PREG_OFFSET_CAPTURE, 0 TSRMLS_CC);
/* Free haystack */
efree(haystack);
@@ -2125,98 +2125,37 @@ magiccheck(struct magic_set *ms, struct magic *m)
FREE_ZVAL(pattern);
return -1;
} else if ((Z_LVAL_P(retval) > 0) && (Z_TYPE_P(subpats) == IS_ARRAY)) {
-
/* Need to fetch global match which equals pmatch[0] */
+ zval **ppzval;
HashTable *ht = Z_ARRVAL_P(subpats);
- HashPosition outer_pos;
- zval *pattern_match = NULL, *pattern_offset = NULL;
-
- zend_hash_internal_pointer_reset_ex(ht, &outer_pos);
-
- if (zend_hash_has_more_elements_ex(ht, &outer_pos) == SUCCESS &&
- zend_hash_move_forward_ex(ht, &outer_pos)) {
-
- zval **ppzval;
-
- /* The first element (should be) is the global match
- Need to move to the inner array to get the global match */
-
- if (zend_hash_get_current_data_ex(ht, (void**)&ppzval, &outer_pos) != FAILURE) {
-
- HashTable *inner_ht;
- HashPosition inner_pos;
- zval **match, **offset;
- zval tmpcopy = **ppzval, matchcopy, offsetcopy;
-
- zval_copy_ctor(&tmpcopy);
- INIT_PZVAL(&tmpcopy);
-
- inner_ht = Z_ARRVAL(tmpcopy);
-
- /* If everything goes according to the master plan
- tmpcopy now contains two elements:
- 0 = the match
- 1 = starting position of the match */
- zend_hash_internal_pointer_reset_ex(inner_ht, &inner_pos);
-
- if (zend_hash_has_more_elements_ex(inner_ht, &inner_pos) == SUCCESS &&
- zend_hash_move_forward_ex(inner_ht, &inner_pos)) {
-
- if (zend_hash_get_current_data_ex(inner_ht, (void**)&match, &inner_pos) != FAILURE)
{
-
- matchcopy = **match;
- zval_copy_ctor(&matchcopy);
- INIT_PZVAL(&matchcopy);
- convert_to_string(&matchcopy);
-
- MAKE_STD_ZVAL(pattern_match);
- Z_STRVAL_P(pattern_match) = (char *)Z_STRVAL(matchcopy);
- Z_STRLEN_P(pattern_match) = Z_STRLEN(matchcopy);
- Z_TYPE_P(pattern_match) = IS_STRING;
-
- zval_dtor(&matchcopy);
- }
+ /* The first element (should be) is the global match
+ Need to move to the inner array to get the global match */
+ if (zend_hash_index_find(ht, 0, (void **)&ppzval) == SUCCESS) {
+ zval **match, **offset;
+ /* If everything goes according to the master plan
+ tmpcopy now contains two elements:
+ 0 = the match
+ 1 = starting position of the match */
+ if (zend_hash_index_find(Z_ARRVAL_PP(ppzval), 0, (void **)&match) == SUCCESS
+ && zend_hash_index_find(Z_ARRVAL_PP(ppzval), 1, (void **)&offset) == SUCCESS) {
+ if (Z_TYPE_PP(match) != IS_STRING || Z_TYPE_PP(offset) != IS_LONG) {
+ goto error_out;
}
-
- if (zend_hash_has_more_elements_ex(inner_ht, &inner_pos) == SUCCESS &&
- zend_hash_move_forward_ex(inner_ht, &inner_pos)) {
-
- if (zend_hash_get_current_data_ex(inner_ht, (void**)&offset, &inner_pos) != FAILURE)
{
-
- offsetcopy = **offset;
- zval_copy_ctor(&offsetcopy);
- INIT_PZVAL(&offsetcopy);
- convert_to_long(&offsetcopy);
-
- MAKE_STD_ZVAL(pattern_offset);
- Z_LVAL_P(pattern_offset) = Z_LVAL(offsetcopy);
- Z_TYPE_P(pattern_offset) = IS_LONG;
-
- zval_dtor(&offsetcopy);
- }
- }
- zval_dtor(&tmpcopy);
- }
-
- if ((pattern_match != NULL) && (pattern_offset != NULL)) {
- ms->search.s += (int)Z_LVAL_P(pattern_offset); /* this is where the match starts */
- ms->search.offset += (size_t)Z_LVAL_P(pattern_offset); /* this is where the match starts
as size_t */
- ms->search.rm_len = Z_STRLEN_P(pattern_match) /* This is the length of the matched pattern
*/;
+ ms->search.s += (int)Z_LVAL_PP(offset); /* this is where the match starts */
+ ms->search.offset += (size_t)Z_LVAL_PP(offset); /* this is where the match starts as
size_t */
+ ms->search.rm_len = Z_STRLEN_PP(match) /* This is the length of the matched pattern */;
v = 0;
-
- efree(pattern_match);
- efree(pattern_offset);
-
} else {
- zval_ptr_dtor(&subpats);
- FREE_ZVAL(retval);
- zval_dtor(pattern);
- FREE_ZVAL(pattern);
- return -1;
+ goto error_out;
}
+ } else {
+error_out:
+ zval_ptr_dtor(&subpats);
+ FREE_ZVAL(retval);
+ zval_dtor(pattern);
+ FREE_ZVAL(pattern);
+ return -1;
}
-
-
} else {
v = 1;
}