]> granicus.if.org Git - php/commitdiff
preliminary fix for bug #73971, more refactoring is needed
authorAnatol Belski <ab@php.net>
Sun, 22 Jan 2017 21:43:53 +0000 (22:43 +0100)
committerAnatol Belski <ab@php.net>
Sun, 22 Jan 2017 21:43:53 +0000 (22:43 +0100)
ext/standard/tests/dir/dir_bug73971.phpt [new file with mode: 0644]
win32/readdir.c
win32/readdir.h

diff --git a/ext/standard/tests/dir/dir_bug73971.phpt b/ext/standard/tests/dir/dir_bug73971.phpt
new file mode 100644 (file)
index 0000000..86cb29a
--- /dev/null
@@ -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==
index 43d5deecfd7fa088533a3663529a59102ec667d5..42b528ad0ad677f86fde72d7700494834564bfce 100644 (file)
@@ -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);
 
index 73058f88042d0cad0d2d104246164d834cfa5a50..495c36a1a9bdcb6f5e3d01155449f5797fefcc15 100644 (file)
@@ -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 */