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?> 38--EXPECTF-- 39# No overflow 001: "0" 400 41 42---------- 43# No overflow 002: "1" 441 45 46---------- 47# No overflow 003: "100" 48100 49 50---------- 51# No overflow 004: "%d" 52%d 53 54---------- 55# No overflow 005: "2K" 562048 57 58---------- 59# No overflow 006: "-1" 60%d 61 62---------- 63# No overflow 007: " -1" 64%d 65 66---------- 67# No overflow 008: "-1 " 68%d 69 70---------- 71# No overflow 009: " -1 " 72%d 73 74---------- 75# Subject overflow 001: "%d" 76 77Warning: Invalid quantity "%d": value is out of range, using overflow result for backwards compatibility in %s on line %d 78%d 79 80---------- 81# Subject overflow 002: "-%d" 82 83Warning: Invalid quantity "-%d": value is out of range, using overflow result for backwards compatibility in %s on line %d 84%d 85 86---------- 87# Subject overflow 003: "-%d" 88 89Warning: Invalid quantity "-%d": value is out of range, using overflow result for backwards compatibility in %s on line %d 90%d 91 92---------- 93# Subject overflow 004: "-2" 94 95Warning: Invalid quantity "-2": value is out of range, using overflow result for backwards compatibility in %s on line %d 96%d 97 98---------- 99# Subject overflow 005: "-1K" 100 101Warning: Invalid quantity "-1K": value is out of range, using overflow result for backwards compatibility in %s on line %d 102%d 103 104---------- 105# Subject overflow 006: "-1 K" 106 107Warning: Invalid quantity "-1 K": value is out of range, using overflow result for backwards compatibility in %s on line %d 108%d 109 110---------- 111# Multiplier overflow 001: "%dK" 112 113Warning: Invalid quantity "%dK": value is out of range, using overflow result for backwards compatibility in %s on line %d 114%d 115 116---------- 117# zend_test_zend_ini_parse_uquantity("-1") === -1 118bool(true) 119