1--TEST--
2Test zend_ini_parse_uquantity() overflow handling
3--EXTENSIONS--
4zend_test
5--FILE--
6<?php
7
8$tests = [
9    'No overflow 001' => '0',
10    'No overflow 002' => '1',
11    'No overflow 003' => '100',
12    'No overflow 004' => strval(PHP_INT_MAX),
13    'No overflow 005' => '2K',
14    'No overflow 006' => '-1',
15    'No overflow 007' => ' -1',
16    'No overflow 008' => '-1 ',
17    'No overflow 009' => ' -1 ',
18    'Subject overflow 001' => base_convert(str_repeat('1', PHP_INT_SIZE*8+1), 2, 10),
19    'Subject overflow 002' => '-'.base_convert(str_repeat('1', PHP_INT_SIZE*8+1), 2, 10),
20    'Subject overflow 003' => strval(PHP_INT_MIN),
21    'Subject overflow 004' => '-2',
22    'Subject overflow 005' => '-1K',
23    'Subject overflow 006' => '-1 K',
24    'Multiplier overflow 001' => strval(PHP_INT_MAX).'K',
25];
26
27foreach ($tests as $name => $value) {
28    printf("# %s: \"%s\"\n", $name, $value);
29    printf("%u\n", zend_test_zend_ini_parse_uquantity($value));
30    print "\n";
31    print "----------\n";
32}
33
34printf("# zend_test_zend_ini_parse_uquantity(\"-1\") === -1\n");
35var_dump(zend_test_zend_ini_parse_uquantity("-1") === -1);
36
37--EXPECTF--
38# No overflow 001: "0"
390
40
41----------
42# No overflow 002: "1"
431
44
45----------
46# No overflow 003: "100"
47100
48
49----------
50# No overflow 004: "%d"
51%d
52
53----------
54# No overflow 005: "2K"
552048
56
57----------
58# No overflow 006: "-1"
59%d
60
61----------
62# No overflow 007: " -1"
63%d
64
65----------
66# No overflow 008: "-1 "
67%d
68
69----------
70# No overflow 009: " -1 "
71%d
72
73----------
74# Subject overflow 001: "%d"
75
76Warning: Invalid quantity "%d": value is out of range, using overflow result for backwards compatibility in %s on line %d
77%d
78
79----------
80# Subject overflow 002: "-%d"
81
82Warning: Invalid quantity "-%d": value is out of range, using overflow result for backwards compatibility in %s on line %d
83%d
84
85----------
86# Subject overflow 003: "-%d"
87
88Warning: Invalid quantity "-%d": value is out of range, using overflow result for backwards compatibility in %s on line %d
89%d
90
91----------
92# Subject overflow 004: "-2"
93
94Warning: Invalid quantity "-2": value is out of range, using overflow result for backwards compatibility in %s on line %d
95%d
96
97----------
98# Subject overflow 005: "-1K"
99
100Warning: Invalid quantity "-1K": value is out of range, using overflow result for backwards compatibility in %s on line %d
101%d
102
103----------
104# Subject overflow 006: "-1 K"
105
106Warning: Invalid quantity "-1 K": value is out of range, using overflow result for backwards compatibility in %s on line %d
107%d
108
109----------
110# Multiplier overflow 001: "%dK"
111
112Warning: Invalid quantity "%dK": value is out of range, using overflow result for backwards compatibility in %s on line %d
113%d
114
115----------
116# zend_test_zend_ini_parse_uquantity("-1") === -1
117bool(true)
118