xref: /PHP-7.0/ext/filter/tests/047.phpt (revision 610c7fbe)
1--TEST--
2Octal integer overflow
3--SKIPIF--
4<?php if (!extension_loaded("filter")) die("skip"); ?>
5--FILE--
6<?php
7function octal_inc($s) {
8	$len = strlen($s);
9	while ($len > 0) {
10		$len--;
11		if ($s[$len] != '7') {
12			$s[$len] = $s[$len] + 1;
13			return $s;
14		}
15		$s[$len] = '0';
16	}
17	return '1'.$s;
18}
19
20
21$s = sprintf("%o", PHP_INT_MAX);
22var_dump(is_long(filter_var('0'.$s, FILTER_VALIDATE_INT, array("flags"=>FILTER_FLAG_ALLOW_OCTAL))));
23
24$s = octal_inc($s);
25var_dump(is_long(filter_var('0'.$s, FILTER_VALIDATE_INT, array("flags"=>FILTER_FLAG_ALLOW_OCTAL))));
26
27$s = sprintf("%o", ~0);
28var_dump(is_long(filter_var('0'.$s, FILTER_VALIDATE_INT, array("flags"=>FILTER_FLAG_ALLOW_OCTAL))));
29
30$s = octal_inc($s);
31var_dump(filter_var('0'.$s, FILTER_VALIDATE_INT, array("flags"=>FILTER_FLAG_ALLOW_OCTAL)));
32?>
33--EXPECT--
34bool(true)
35bool(true)
36bool(true)
37bool(false)
38