Skip to content

Commit a65b8ab

Browse files
committed
Merge branch 'PHP-7.2' into PHP-7.3
* PHP-7.2: Fixed bug #78910 Fix #78878: Buffer underflow in bc_shift_addsub Fix test Fix #78862: link() silently truncates after a null byte on Windows Fix #78863: DirectoryIterator class silently truncates after a null byte
2 parents 518a160 + d348cfb commit a65b8ab

File tree

9 files changed

+88
-7
lines changed

9 files changed

+88
-7
lines changed

ext/bcmath/libbcmath/src/str2num.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@ bc_str2num (bc_num *num, char *str, int scale)
5757
zero_int = FALSE;
5858
if ( (*ptr == '+') || (*ptr == '-')) ptr++; /* Sign */
5959
while (*ptr == '0') ptr++; /* Skip leading zeros. */
60-
while (isdigit((int)*ptr)) ptr++, digits++; /* digits */
60+
while (*ptr >= '0' && *ptr <= '9') ptr++, digits++; /* digits */
6161
if (*ptr == '.') ptr++; /* decimal point */
62-
while (isdigit((int)*ptr)) ptr++, strscale++; /* digits */
62+
while (*ptr >= '0' && *ptr <= '9') ptr++, strscale++; /* digits */
6363
if ((*ptr != '\0') || (digits+strscale == 0))
6464
{
6565
*num = bc_copy_num (BCG(_zero_));

ext/bcmath/tests/bug78878.phpt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
--TEST--
2+
Bug #78878 (Buffer underflow in bc_shift_addsub)
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded('bcmath')) die('skip bcmath extension not available');
6+
?>
7+
--FILE--
8+
<?php
9+
print @bcmul("\xB26483605105519922841849335928742092", bcpowmod(2, 65535, -4e-4));
10+
?>
11+
--EXPECT--
12+
bc math warning: non-zero scale in modulus
13+
0

ext/exif/exif.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3138,7 +3138,10 @@ static int exif_process_IFD_in_MAKERNOTE(image_info_type *ImageInfo, char * valu
31383138
/*exif_error_docref(NULL EXIFERR_CC, ImageInfo, E_NOTICE, "check (%s)", maker_note->make?maker_note->make:"");*/
31393139
if (maker_note->make && (!ImageInfo->make || strcmp(maker_note->make, ImageInfo->make)))
31403140
continue;
3141-
if (maker_note->id_string && strncmp(maker_note->id_string, value_ptr, maker_note->id_string_len))
3141+
if (maker_note->model && (!ImageInfo->model || strcmp(maker_note->model, ImageInfo->model)))
3142+
continue;
3143+
if (maker_note->id_string && value_len >= maker_note->id_string_len
3144+
&& strncmp(maker_note->id_string, value_ptr, maker_note->id_string_len))
31423145
continue;
31433146
break;
31443147
}

ext/exif/tests/bug78910.phpt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
--TEST--
2+
Bug #78910: Heap-buffer-overflow READ in exif (OSS-Fuzz #19044)
3+
--FILE--
4+
<?php
5+
6+
var_dump(exif_read_data('data:image/jpg;base64,TU0AKgAAAAwgICAgAAIBDwAEAAAAAgAAACKSfCAgAAAAAEZVSklGSUxN'));
7+
8+
?>
9+
--EXPECTF--
10+
Notice: exif_read_data(): Read from TIFF: tag(0x927C, MakerNote ): Illegal format code 0x2020, switching to BYTE in %s on line %d
11+
12+
Warning: exif_read_data(): Process tag(x927C=MakerNote ): Illegal format code 0x2020, suppose BYTE in %s on line %d
13+
14+
Warning: exif_read_data(): IFD data too short: 0x0000 offset 0x000C in %s on line %d
15+
16+
Warning: exif_read_data(): Invalid TIFF file in %s on line %d
17+
bool(false)

ext/spl/spl_directory.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -708,10 +708,10 @@ void spl_filesystem_object_construct(INTERNAL_FUNCTION_PARAMETERS, zend_long cto
708708

709709
if (SPL_HAS_FLAG(ctor_flags, DIT_CTOR_FLAGS)) {
710710
flags = SPL_FILE_DIR_KEY_AS_PATHNAME|SPL_FILE_DIR_CURRENT_AS_FILEINFO;
711-
parsed = zend_parse_parameters(ZEND_NUM_ARGS(), "s|l", &path, &len, &flags);
711+
parsed = zend_parse_parameters(ZEND_NUM_ARGS(), "p|l", &path, &len, &flags);
712712
} else {
713713
flags = SPL_FILE_DIR_KEY_AS_PATHNAME|SPL_FILE_DIR_CURRENT_AS_SELF;
714-
parsed = zend_parse_parameters(ZEND_NUM_ARGS(), "s", &path, &len);
714+
parsed = zend_parse_parameters(ZEND_NUM_ARGS(), "p", &path, &len);
715715
}
716716
if (SPL_HAS_FLAG(ctor_flags, SPL_FILE_DIR_SKIPDOTS)) {
717717
flags |= SPL_FILE_DIR_SKIPDOTS;

ext/spl/tests/bug54291.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Bug #54291 (Crash iterating DirectoryIterator for dir name starting with \0)
55
$dir = new DirectoryIterator("\x00/abc");
66
$dir->isFile();
77
--EXPECTF--
8-
Fatal error: Uncaught UnexpectedValueException: Failed to open directory "" in %s:%d
8+
Fatal error: Uncaught UnexpectedValueException: DirectoryIterator::__construct() expects parameter 1 to be a valid path, string given in %s:%d
99
Stack trace:
1010
#0 %s(%d): DirectoryIterator->__construct('\x00/abc')
1111
#1 {main}

ext/spl/tests/bug78863.phpt

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
--TEST--
2+
Bug #78863 (DirectoryIterator class silently truncates after a null byte)
3+
--FILE--
4+
<?php
5+
$dir = __DIR__ . '/bug78863';
6+
mkdir($dir);
7+
touch("$dir/bad");
8+
mkdir("$dir/sub");
9+
touch("$dir/sub/good");
10+
11+
$it = new DirectoryIterator(__DIR__ . "/bug78863\0/sub");
12+
foreach ($it as $fileinfo) {
13+
if (!$fileinfo->isDot()) {
14+
var_dump($fileinfo->getFilename());
15+
}
16+
}
17+
?>
18+
--EXPECTF--
19+
Fatal error: Uncaught UnexpectedValueException: DirectoryIterator::__construct() expects parameter 1 to be a valid path, string given in %s:%d
20+
Stack trace:
21+
#0 %s(%d): DirectoryIterator->__construct('%s')
22+
#1 {main}
23+
thrown in %s on line %d
24+
--CLEAN--
25+
<?php
26+
$dir = __DIR__ . '/bug78863';
27+
unlink("$dir/sub/good");
28+
rmdir("$dir/sub");
29+
unlink("$dir/bad");
30+
rmdir($dir);
31+
?>

ext/standard/link_win32.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ PHP_FUNCTION(link)
211211

212212
/*First argument to link function is the target and hence should go to frompath
213213
Second argument to link function is the link itself and hence should go to topath */
214-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss", &frompath, &frompath_len, &topath, &topath_len) == FAILURE) {
214+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "pp", &frompath, &frompath_len, &topath, &topath_len) == FAILURE) {
215215
return;
216216
}
217217

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
--TEST--
2+
Bug #78862 (link() silently truncates after a null byte on Windows)
3+
--FILE--
4+
<?php
5+
file_put_contents(__DIR__ . '/bug78862.target', 'foo');
6+
var_dump(link(__DIR__ . "/bug78862.target\0more", __DIR__ . "/bug78862.link\0more"));
7+
var_dump(file_exists(__DIR__ . '/bug78862.link'));
8+
?>
9+
--EXPECTF--
10+
Warning: link() expects parameter 1 to be a valid path, string given in %s on line %d
11+
NULL
12+
bool(false)
13+
--CLEAN--
14+
<?php
15+
unlink(__DIR__ . '/bug78862.target');
16+
unlink(__DIR__ . '/bug78862.link');
17+
?>

0 commit comments

Comments
 (0)