com php-src: preliminary fix for bug #73971, more refactoring is needed: ext/standard/tests/dir/dir_bug73971.phpt win3 2/readdir.c win32/readdir.h
| From: | Anatol Belski | Date: | Sun, 22 Jan 2017 21:43:53 +0000 |
| Subject: | com php-src: preliminary fix for bug #73971, more refactoring is needed: ext/standard/tests/dir/dir_bug73971.phpt win3 2/readdir.c win32/readdir.h | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-96843@lists.php.net to get a copy of this message | ||
Commit: 609507024f3e8da406d71aaabd04c1624c01ada6
Author: Anatol Belski <ab@php.net> Sun, 22 Jan 2017 22:43:53 +0100
Parents: 8782e847b4f0e53b4c0f3e89944b4b7106c4d28f
Branches: master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=609507024f3e8da406d71aaabd04c1624c01ada6
Log:
preliminary fix for bug #73971, more refactoring is needed
Bugs:
https://bugs.php.net/73971
Changed paths:
A ext/standard/tests/dir/dir_bug73971.phpt
M win32/readdir.c
M win32/readdir.h
Diff:
diff --git a/ext/standard/tests/dir/dir_bug73971.phpt b/ext/standard/tests/dir/dir_bug73971.phpt
new file mode 100644
index 0000000..86cb29a
--- /dev/null
+++ b/ext/standard/tests/dir/dir_bug73971.phpt
@@ -0,0 +1,54 @@
+--TEST--
+Bug #73971 Filename got limited to MAX_PATH on Win32 when scan directory
+--SKIPIF--
+<?php
+if (substr(PHP_OS, 0, 3) != 'WIN') {
+ die("skip Valid only on Windows");
+}
+?>
+--FILE--
+<?php
+$base = __DIR__ . DIRECTORY_SEPARATOR . "bug73971";
+$filename = $base . DIRECTORY_SEPARATOR . str_repeat('テスト', 48); // 144 glyph
here, less than 256
+
+mkdir($base);
+mkdir($filename); // created correctly
+
+var_dump(basename($filename)); // 432 bytes here, more than 256
+
+echo "\ntest dir()\n";
+$d = dir($base);
+while (false !== ($entry = $d->read())) {
+ var_dump($entry);
+}
+$d->close();
+
+echo "\ntest DirectoryIterator\n";
+$dir = new DirectoryIterator($base);
+foreach ($dir as $finfo) {
+ var_dump($finfo->getFilename());
+}
+
+?>
+==DONE==
+--CLEAN--
+<?php
+$base = __DIR__ . DIRECTORY_SEPARATOR . "bug73971";
+$filename = $base . DIRECTORY_SEPARATOR . str_repeat('テスト', 48);
+
+rmdir($filename);
+rmdir($base);
+?>
+--EXPECTF--
+string(432)
"テストテストテストテストテストテストテストテストテストテストテストテストテストテストテストテストテストテストテストテストテストテストテストテストテストテストテストテストテストテストテストテストテストテストテストテストテストテストテストテストテストテストテストテストテストテストテストテスト"
+
+test dir()
+string(1) "."
+string(2) ".."
+string(432)
"テストテストテストテストテストテストテストテストテストテストテストテストテストテストテストテストテストテストテストテストテストテストテストテストテストテストテストテストテストテストテストテストテストテストテストテストテストテストテストテストテストテストテストテストテストテストテストテスト"
+
+test DirectoryIterator
+string(1) "."
+string(2) ".."
+string(432)
"テストテストテストテストテストテストテストテストテストテストテストテストテストテストテストテストテストテストテストテストテストテストテストテストテストテストテストテストテストテストテストテストテストテストテストテストテストテストテストテストテストテストテストテストテストテストテストテスト"
+==DONE==
diff --git a/win32/readdir.c b/win32/readdir.c
index 43d5dee...42b528a 100644
--- a/win32/readdir.c
+++ b/win32/readdir.c
@@ -103,7 +103,7 @@ struct dirent *readdir(DIR *dp)
/* wide to utf8 failed, should never happen. */
return NULL;
}
- strlcpy(dp->dent.d_name, _tmp, _MAX_FNAME+1);
+ strlcpy(dp->dent.d_name, _tmp, _MAX_FNAME*4+1);
dp->dent.d_reclen = (unsigned short)strlen(dp->dent.d_name);
free(_tmp);
@@ -138,7 +138,7 @@ int readdir_r(DIR *dp, struct dirent *entry, struct dirent **result)
result = NULL;
return 0;
}
- strlcpy(dp->dent.d_name, _tmp, _MAX_FNAME+1);
+ strlcpy(dp->dent.d_name, _tmp, _MAX_FNAME*4+1);
dp->dent.d_reclen = (unsigned short)strlen(dp->dent.d_name);
free(_tmp);
diff --git a/win32/readdir.h b/win32/readdir.h
index 73058f8..495c36a 100644
--- a/win32/readdir.h
+++ b/win32/readdir.h
@@ -22,7 +22,7 @@ struct dirent {
long d_ino; /* inode (always 1 in WIN32) */
off_t d_off; /* offset to this dirent */
unsigned short d_reclen; /* length of d_name */
- char d_name[PHP_WIN32_IOUTIL_MAXPATHLEN + 1]; /* filename (null terminated) */
+ char d_name[_MAX_FNAME*4+1]; /* filename with care about UTF-8 (null terminated) */
};
/* typedef DIR - not the same as Unix */