diff options
-rw-r--r-- | ext/standard/tests/dir/dir_bug73971.phpt | 54 | ||||
-rw-r--r-- | win32/readdir.c | 4 | ||||
-rw-r--r-- | win32/readdir.h | 2 |
3 files changed, 57 insertions, 3 deletions
diff --git a/ext/standard/tests/dir/dir_bug73971.phpt b/ext/standard/tests/dir/dir_bug73971.phpt new file mode 100644 index 0000000000..86cb29ac58 --- /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 43d5deecfd..42b528ad0a 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 73058f8804..495c36a1a9 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 */ |