rfc:range_checks_for_64_bit
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision | ||
rfc:range_checks_for_64_bit [2015/08/24 15:33] – ab | rfc:range_checks_for_64_bit [2015/08/24 17:06] – ab | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== PHP RFC: Range checks for external | + | ====== PHP RFC: Range checks for external |
* Version: 0.9 | * Version: 0.9 | ||
* Date: 2015-08-24 | * Date: 2015-08-24 | ||
Line 13: | Line 13: | ||
===== Proposal ===== | ===== Proposal ===== | ||
- | It is suggested to implement | + | It is suggested to implement additional formats for ZPP, that are explicitly require |
- | * strings with 32-bit length | + | * strings with 32-bit length |
- | * 32-bit integers | + | * 32-bit integers |
on affected platforms only. In addition, it is suggested to implement a set of macros for range checks and comparison. | on affected platforms only. In addition, it is suggested to implement a set of macros for range checks and comparison. | ||
Line 33: | Line 33: | ||
# define ZEND_LONG_INT_OVFL(zlong) ((zlong) > (zend_long)INT_MAX) | # define ZEND_LONG_INT_OVFL(zlong) ((zlong) > (zend_long)INT_MAX) | ||
# define ZEND_LONG_INT_UDFL(zlong) ((zlong) < (zend_long)INT_MIN) | # define ZEND_LONG_INT_UDFL(zlong) ((zlong) < (zend_long)INT_MIN) | ||
+ | #endif | ||
+ | |||
+ | #if SIZEOF_INT == SIZEOF_ZEND_LONG | ||
+ | # define ZEND_LONG_UINT_OVFL(zl) (0) | ||
+ | #else | ||
+ | # define ZEND_LONG_UINT_OVFL(zlong) ((zlong) < 0 || (zlong) > (zend_long)UINT_MAX) | ||
#endif | #endif | ||
#define ZEND_SIZE_T_INT_OVFL(size) ((size) > (size_t)INT_MAX) | #define ZEND_SIZE_T_INT_OVFL(size) ((size) > (size_t)INT_MAX) | ||
+ | |||
+ | #if SIZEOF_INT == SIZEOF_SIZE_T | ||
+ | # define ZEND_SIZE_T_UINT_OVFL(size) (0) | ||
+ | #else | ||
+ | # define ZEND_SIZE_T_UINT_OVFL(size) ((size) > (size_t)UINT_MAX) | ||
+ | #endif | ||
</ | </ | ||
Line 48: | Line 60: | ||
</ | </ | ||
- | All the macros should be put into a dedicated header, so any extensions can be put there. | + | All the macros should be put into a dedicated header, so any extensions |
==== Proposed ZPP changes ==== | ==== Proposed ZPP changes ==== | ||
Line 54: | Line 66: | ||
Introducing new formats | Introducing new formats | ||
- | * ' | + | * ' |
- | * ' | + | * ' |
+ | * ' | ||
+ | * ' | ||
The behaviour of the options: | The behaviour of the options: | ||
Line 67: | Line 81: | ||
Here is the real case from the current code base, the irrelevant declarations and code are removed. Consider the signature in the underlaying API [[http:// | Here is the real case from the current code base, the irrelevant declarations and code are removed. Consider the signature in the underlaying API [[http:// | ||
+ | |||
+ | The original piece of code | ||
<code c> | <code c> | ||
Line 139: | Line 155: | ||
===== Backward Incompatible Changes ===== | ===== Backward Incompatible Changes ===== | ||
- | Several new warnings or harder error handling might be introduced with the new range checks. | + | Several new warnings or harder error handling might be introduced with the new range checks. |
===== Proposed PHP Version(s) ===== | ===== Proposed PHP Version(s) ===== | ||
Line 167: | Line 183: | ||
===== Future Scope ===== | ===== Future Scope ===== | ||
+ | |||
Having this minimalistic start as a base, the topic of overflows in the mathematical operations can be entered. This topic is not handled by this RFC. | Having this minimalistic start as a base, the topic of overflows in the mathematical operations can be entered. This topic is not handled by this RFC. | ||
+ | |||
+ | Also, some good patterns for other cases can be added later by need. Like compare int vs size_t, or compare variables with different sizes. | ||
===== Proposed Voting Choices ===== | ===== Proposed Voting Choices ===== | ||
Line 174: | Line 193: | ||
===== Patches and Tests ===== | ===== Patches and Tests ===== | ||
- | TBD. | + | The implementation of the base functionality is trivial and can be done if the proposed strategy is accepted. Many places in the core extensions related to libxml2, openssl, tidy, etc. are obvious and will be addressed already before merging. |
===== Implementation ===== | ===== Implementation ===== |
rfc/range_checks_for_64_bit.txt · Last modified: 2017/09/22 13:28 by 127.0.0.1