]> granicus.if.org Git - php/commitdiff
Add range inference for ZEND_STRLEN
authorNikita Popov <nikic@php.net>
Sat, 24 Sep 2016 19:03:13 +0000 (21:03 +0200)
committerNikita Popov <nikic@php.net>
Sat, 24 Sep 2016 20:43:27 +0000 (22:43 +0200)
On 32-bit systems we conservatively allow negative lengths.
On 64-bit systems, the range could additionally be restricted to
the canonical 48-bit size.

ext/opcache/Optimizer/zend_inference.c

index 7505e1475caefd9e99f44fb38a946acb55dbd66b..4e7db1a75b38dfa411053e710df7ac39fec2c493 100644 (file)
@@ -1595,6 +1595,20 @@ int zend_inference_calc_range(const zend_op_array *op_array, zend_ssa *ssa, int
                                }
                        }
                        break;
+               case ZEND_STRLEN:
+                       if (ssa->ops[line].result_def == var) {
+#if SIZEOF_ZEND_LONG == 4
+                               /* The length of a string is a non-negative integer. However, on 32-bit
+                                * platforms overflows into negative lengths may occur, so it's better
+                                * to not assume any particular range. */
+                               tmp->min = ZEND_LONG_MIN;
+#else
+                               tmp->min = 0;
+#endif
+                               tmp->max = ZEND_LONG_MAX;
+                               return 1;
+                       }
+                       break;
                case ZEND_DO_FCALL:
                case ZEND_DO_ICALL:
                case ZEND_DO_UCALL: