Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rmtree can not be called from a directory with a SJIS character with trailing 0x5c in path. #9099

Open
p5pRT opened this issue Nov 2, 2007 · 7 comments

Comments

@p5pRT
Copy link

p5pRT commented Nov 2, 2007

Migrated from rt.perl.org#47115 (status was 'open')

Searchable as RT47115$

@p5pRT
Copy link
Author

p5pRT commented Nov 2, 2007

From Gadi.Reinhorn@mathworks.com

This is a bug report for perl from greinhorn@​mathworks.com,
generated with the help of perlbug 1.35 running under perl v5.8.8.

I am calling rmtree on a path that contains with a SJIS character with trailing 0x5c. I've debugged the issue and I believe the root cause is the call to
  my $oldpwd = getcwd or do {
in line 287 of $PERL\win32\lib\File\Path.pm.

The way to reproduce this issue is​:
1) Log on to a Japanese windows machine.
2) cd to a temporary directory
3) Put the following code in a batch file.

mkdir �}*\END
cd *end
mkdir *\Ž|M
cd *M

4) Run the batch file.
5) Run the following Perl from with in the directory with the SJIS characters.
use File​::Path;
use Cwd;
my $tempDir = $ENV{'TEMP'};
mkdir("$tempDir\\gadi\\");
my $dirToRemove = "$tempDir\\gadi\\Dummy";
mkdir($dirToRemove);
my $resultFromCWD = getcwd();
print $resultFromCWD . "\n" . `pwd`;
rmtree($dirToRemove);

You should get a message like the following​:

C​:\temp\gadi\�}*\END\*\Ž|M>S​:\Akernel\matlab\sys\perl\win32\bin\perl.exe S​:\Work
\perlBug\bugInRmtree.pl
C​:/temp/gadi/�}�EEND/�EŽ|M
C​:/temp/gadi/�}*\END/*\Ž|M
Can't return to C​:/temp/gadi/�}�EEND/�EŽ|M from C​:\TEMP\gadi\Dummy (No such file
or directory) at S​:\Work\perlBug\bugInRmtree.pl line 9

Note the difference between​:
C​:/temp/gadi/�}�EEND/�EŽ|M
C​:/temp/gadi/�}*\END/*\Ž|M

I think this proves that the issue is with the call to getcwd.---
Flags​:
  category=library
  severity=medium


This perlbug was built using Perl v5.8.8 - Tue Jan 23 15​:57​:26 2007
It is being executed now by Perl v5.8.8 - Thu Jun 7 18​:52​:55 2007.

Site configuration information for perl v5.8.8​:

Configured by batserve at Thu Jun 7 18​:52​:55 2007.

Summary of my perl5 (revision 5 version 8 subversion 8) configuration​:
  Platform​:
  osname=MSWin32, osvers=5.1, archname=MSWin32-x86-multi-thread
  uname=''
  config_args='undef'
  hint=recommended, useposix=true, d_sigaction=undef
  usethreads=define use5005threads=undef useithreads=define usemultiplicity=define
  useperlio=define d_sfio=undef uselargefiles=define usesocks=undef
  use64bitint=undef use64bitall=undef uselongdouble=undef
  usemymalloc=n, bincompat5005=undef
  Compiler​:
  cc='cl', ccflags ='-nologo -GF -W3 -MD -Zi -DNDEBUG -O1 -DWIN32 -D_CONSOLE -DNO_STRICT -DHAVE_DES_FCRYPT -DPERL_IMPLICIT_CONTEXT -DPERL_IMPLICIT_SYS -DUSE_PERLIO -DPERL_MSVCRT_READFIX',
  optimize='-MD -Zi -DNDEBUG -O1',
  cppflags='-DWIN32'
  ccversion='13.10.3077', gccversion='', gccosandvers=''
  intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234
  d_longlong=undef, longlongsize=8, d_longdbl=define, longdblsize=10
  ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='__int64', lseeksize=8
  alignbytes=8, prototype=define
  Linker and Libraries​:
  ld='link', ldflags ='-nologo -nodefaultlib -debug -opt​:ref,icf -libpath​:"\\mathworks\hub\share\apps\BuildTools\win32\perl\perl-5.8.8-tmw-022\lib\CORE" -machine​:x86'
  libpth="C​:\Program Files\Microsoft Visual Studio .NET 2003\VC7\lib"
  libs= oldnames.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib netapi32.lib uuid.lib ws2_32.lib mpr.lib winmm.lib version.lib odbc32.lib odbccp32.lib msvcrt.lib
  perllibs= oldnames.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib netapi32.lib uuid.lib ws2_32.lib mpr.lib winmm.lib version.lib odbc32.lib odbccp32.lib msvcrt.lib
  libc=msvcrt.lib, so=dll, useshrplib=yes, libperl=perl58.lib
  gnulibc_version=''
  Dynamic Linking​:
  dlsrc=dl_win32.xs, dlext=dll, d_dlsymun=undef, ccdlflags=' '
  cccdlflags=' ', lddlflags='-dll -nologo -nodefaultlib -debug -opt​:ref,icf -libpath​:"\\mathworks\hub\share\apps\BuildTools\win32\perl\perl-5.8.8-tmw-022\lib\CORE" -machine​:x86'

Locally applied patches​:
  ACTIVEPERL_LOCAL_PATCHES_ENTRY
  Iin_load_module moved for compatibility with build 806
  Avoid signal flag SA_RESTART for older versions of HP-UX
  PerlEx support in CGI​::Carp
  Less verbose ExtUtils​::Install and Pod​::Find
  Patch for CAN-2005-0448 from Debian with modifications
  Rearrange @​INC so that 'site' is searched before 'perl'
  Partly reverted 24733 to preserve binary compatibility
  29930 win32.c typo in #define MULTIPLICITY
  29868 win32_async_check() can still loop indefinitely
  29690,29732 ANSIfy the PATH environment variable on Windows
  29689 Add error handling to win32_ansipath
  29675 Use short pathnames in $^X and @​INC
  29607,29676 allow blib.pm to be used for testing Win32 module
  29605 Implement killpg() for MSWin32
  29598 cwd() to return the short pathname
  29597 let readdir() return the alternate filename
  29590 Don't destroy the Unicode system environment on Perl startup
  29528 get ext/Win32/Win32.xs to compile on cygwin
  29509,29510,29511 Move Win32​::* functions into Win32 module
  29483 Move Win32 from win32/ext/Win32 to ext/Win32
  29481 Makefile.PL changes to compile Win32.xs using cygwin
  28671 Define PERL_NO_DEV_RANDOM on Windows
  28376 Add error checks after execing PL_cshname or PL_sh_path
  28305 Pod​::Html should not convert \"foo\" into ``foo''
  27833 Change anchor generation in Pod​::Html for '=item item 2'
  27832,27847 fix Pod​::Html​::depod() for multi-line strings
  27736 Make perl_fini() run with Sun WorkShop compiler
  27719 Document the functions htmlify() and anchorify() in Pod​::Html
  27619 Bug in Term​::ReadKey being triggered by a bug in Term​::ReadLine
  27549 Move DynaLoader.o into libperl.so
  27528 win32_pclose() error exit doesn't unlock mutex
  27527 win32_async_check() can loop indefinitely
  27515 ignore directories when searching @​INC
  27359 Fix -d​:Foo=bar syntax
  27210 Fix quote typo in c2ph
  27203 Allow compiling swigged C++ code
  27200 Make stat() on Windows handle trailing slashes correctly
  27194 Get perl_fini() running on HP-UX again
  27133 Initialise lastparen in the regexp structure
  27061 L<PerlIO> and Pod​::Html
  27034 Avoid \"Prototype mismatch\" warnings with autouse
  26970 Make Passive mode the default for Net​::FTP
  26921 Avoid getprotobyname/number calls in IO​::Socket​::INET
  26897,26903 Make common IPPROTO_* constants always available
  26670 Make '-s' on the shebang line parse -foo=bar switches
  26637 Make Borland and MinGW happy with change 26379
  26536 INSTALLSCRIPT versus INSTALLDIRS
  26379 Fix alarm() for Windows 2003
  26087 Storable 0.1 compatibility
  25861 IO​::File performace issue
  25084 long groups entry could cause memory exhaustion
  24699 ICMP_UNREACHABLE handling in Net​::Ping


@​INC for perl v5.8.8​:
  D​:/share/apps/BuildTools/win32/perl/perl-5.8.8-tmw-022/lib
  D​:/share/apps/BuildTools/win32/perl/perl-5.8.8-tmw-022/site/lib
  .


Environment for perl v5.8.8​:
  HOME (unset)
  LANG (unset)
  LANGUAGE (unset)
  LD_LIBRARY_PATH (unset)
  LOGDIR (unset)
  PATH=D​:\share\apps\BuildTools\MKSTK_9.0p2\mksnt;D​:\share\apps\BuildTools\1.2\win32\bin;D​:\share\apps\BuildTools\win32\perl\perl-5.8.8-tmw-022\bin;D​:\win32\apps\gnat\3.15p\bin;S​:\Akernel\matlab\bin;S​:\Akernel\matlab\bin\win32;D​:\share\apps\bat\bat2.8.8.1\win32;D​:\share\apps\bat\bat2.8.8.1\share;C​:\WINNT\System32;C​:\WINNT;C​:\WINNT\System32\Wbem;C​:\Perl\bin;C​:\Applications\Executive Software\DiskeeperWorkstation\;C​:\Applications\reskit;C​:\Program Files\Microsoft Visual Studio .NET 2003\Common7\Tools;C​:\Applications\Microsoft Visual Studio\VC98\Bin;C​:\Applications\Microsoft Visual Studio\Common\MSDev98\Bin;\\mathworks\hub\bat\win2000\bin;\\mathworks\hub\bat\nt\bin;C​:\Applications\CA\SharedComponents\ScanEngine;C​:\Applications\CA\SharedComponents\CAUpdate\;C​:\Applications\CA\SharedComponents\ThirdParty\;C​:\Applications\CA\SharedComponents\SubscriptionLicense\;C​:\Applications\CA\eTrustITM
  PERL=C​:\Perl\bin\perl.exe
  PERL_BADLANG (unset)
  SHELL (unset)

1 similar comment
@p5pRT
Copy link
Author

p5pRT commented Nov 2, 2007

From Gadi.Reinhorn@mathworks.com

This is a bug report for perl from greinhorn@​mathworks.com,
generated with the help of perlbug 1.35 running under perl v5.8.8.

I am calling rmtree on a path that contains with a SJIS character with trailing 0x5c. I've debugged the issue and I believe the root cause is the call to
  my $oldpwd = getcwd or do {
in line 287 of $PERL\win32\lib\File\Path.pm.

The way to reproduce this issue is​:
1) Log on to a Japanese windows machine.
2) cd to a temporary directory
3) Put the following code in a batch file.

mkdir �}*\END
cd *end
mkdir *\Ž|M
cd *M

4) Run the batch file.
5) Run the following Perl from with in the directory with the SJIS characters.
use File​::Path;
use Cwd;
my $tempDir = $ENV{'TEMP'};
mkdir("$tempDir\\gadi\\");
my $dirToRemove = "$tempDir\\gadi\\Dummy";
mkdir($dirToRemove);
my $resultFromCWD = getcwd();
print $resultFromCWD . "\n" . `pwd`;
rmtree($dirToRemove);

You should get a message like the following​:

C​:\temp\gadi\�}*\END\*\Ž|M>S​:\Akernel\matlab\sys\perl\win32\bin\perl.exe S​:\Work
\perlBug\bugInRmtree.pl
C​:/temp/gadi/�}�EEND/�EŽ|M
C​:/temp/gadi/�}*\END/*\Ž|M
Can't return to C​:/temp/gadi/�}�EEND/�EŽ|M from C​:\TEMP\gadi\Dummy (No such file
or directory) at S​:\Work\perlBug\bugInRmtree.pl line 9

Note the difference between​:
C​:/temp/gadi/�}�EEND/�EŽ|M
C​:/temp/gadi/�}*\END/*\Ž|M

I think this proves that the issue is with the call to getcwd.---
Flags​:
  category=library
  severity=medium


This perlbug was built using Perl v5.8.8 - Tue Jan 23 15​:57​:26 2007
It is being executed now by Perl v5.8.8 - Thu Jun 7 18​:52​:55 2007.

Site configuration information for perl v5.8.8​:

Configured by batserve at Thu Jun 7 18​:52​:55 2007.

Summary of my perl5 (revision 5 version 8 subversion 8) configuration​:
  Platform​:
  osname=MSWin32, osvers=5.1, archname=MSWin32-x86-multi-thread
  uname=''
  config_args='undef'
  hint=recommended, useposix=true, d_sigaction=undef
  usethreads=define use5005threads=undef useithreads=define usemultiplicity=define
  useperlio=define d_sfio=undef uselargefiles=define usesocks=undef
  use64bitint=undef use64bitall=undef uselongdouble=undef
  usemymalloc=n, bincompat5005=undef
  Compiler​:
  cc='cl', ccflags ='-nologo -GF -W3 -MD -Zi -DNDEBUG -O1 -DWIN32 -D_CONSOLE -DNO_STRICT -DHAVE_DES_FCRYPT -DPERL_IMPLICIT_CONTEXT -DPERL_IMPLICIT_SYS -DUSE_PERLIO -DPERL_MSVCRT_READFIX',
  optimize='-MD -Zi -DNDEBUG -O1',
  cppflags='-DWIN32'
  ccversion='13.10.3077', gccversion='', gccosandvers=''
  intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234
  d_longlong=undef, longlongsize=8, d_longdbl=define, longdblsize=10
  ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='__int64', lseeksize=8
  alignbytes=8, prototype=define
  Linker and Libraries​:
  ld='link', ldflags ='-nologo -nodefaultlib -debug -opt​:ref,icf -libpath​:"\\mathworks\hub\share\apps\BuildTools\win32\perl\perl-5.8.8-tmw-022\lib\CORE" -machine​:x86'
  libpth="C​:\Program Files\Microsoft Visual Studio .NET 2003\VC7\lib"
  libs= oldnames.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib netapi32.lib uuid.lib ws2_32.lib mpr.lib winmm.lib version.lib odbc32.lib odbccp32.lib msvcrt.lib
  perllibs= oldnames.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib netapi32.lib uuid.lib ws2_32.lib mpr.lib winmm.lib version.lib odbc32.lib odbccp32.lib msvcrt.lib
  libc=msvcrt.lib, so=dll, useshrplib=yes, libperl=perl58.lib
  gnulibc_version=''
  Dynamic Linking​:
  dlsrc=dl_win32.xs, dlext=dll, d_dlsymun=undef, ccdlflags=' '
  cccdlflags=' ', lddlflags='-dll -nologo -nodefaultlib -debug -opt​:ref,icf -libpath​:"\\mathworks\hub\share\apps\BuildTools\win32\perl\perl-5.8.8-tmw-022\lib\CORE" -machine​:x86'

Locally applied patches​:
  ACTIVEPERL_LOCAL_PATCHES_ENTRY
  Iin_load_module moved for compatibility with build 806
  Avoid signal flag SA_RESTART for older versions of HP-UX
  PerlEx support in CGI​::Carp
  Less verbose ExtUtils​::Install and Pod​::Find
  Patch for CAN-2005-0448 from Debian with modifications
  Rearrange @​INC so that 'site' is searched before 'perl'
  Partly reverted 24733 to preserve binary compatibility
  29930 win32.c typo in #define MULTIPLICITY
  29868 win32_async_check() can still loop indefinitely
  29690,29732 ANSIfy the PATH environment variable on Windows
  29689 Add error handling to win32_ansipath
  29675 Use short pathnames in $^X and @​INC
  29607,29676 allow blib.pm to be used for testing Win32 module
  29605 Implement killpg() for MSWin32
  29598 cwd() to return the short pathname
  29597 let readdir() return the alternate filename
  29590 Don't destroy the Unicode system environment on Perl startup
  29528 get ext/Win32/Win32.xs to compile on cygwin
  29509,29510,29511 Move Win32​::* functions into Win32 module
  29483 Move Win32 from win32/ext/Win32 to ext/Win32
  29481 Makefile.PL changes to compile Win32.xs using cygwin
  28671 Define PERL_NO_DEV_RANDOM on Windows
  28376 Add error checks after execing PL_cshname or PL_sh_path
  28305 Pod​::Html should not convert \"foo\" into ``foo''
  27833 Change anchor generation in Pod​::Html for '=item item 2'
  27832,27847 fix Pod​::Html​::depod() for multi-line strings
  27736 Make perl_fini() run with Sun WorkShop compiler
  27719 Document the functions htmlify() and anchorify() in Pod​::Html
  27619 Bug in Term​::ReadKey being triggered by a bug in Term​::ReadLine
  27549 Move DynaLoader.o into libperl.so
  27528 win32_pclose() error exit doesn't unlock mutex
  27527 win32_async_check() can loop indefinitely
  27515 ignore directories when searching @​INC
  27359 Fix -d​:Foo=bar syntax
  27210 Fix quote typo in c2ph
  27203 Allow compiling swigged C++ code
  27200 Make stat() on Windows handle trailing slashes correctly
  27194 Get perl_fini() running on HP-UX again
  27133 Initialise lastparen in the regexp structure
  27061 L<PerlIO> and Pod​::Html
  27034 Avoid \"Prototype mismatch\" warnings with autouse
  26970 Make Passive mode the default for Net​::FTP
  26921 Avoid getprotobyname/number calls in IO​::Socket​::INET
  26897,26903 Make common IPPROTO_* constants always available
  26670 Make '-s' on the shebang line parse -foo=bar switches
  26637 Make Borland and MinGW happy with change 26379
  26536 INSTALLSCRIPT versus INSTALLDIRS
  26379 Fix alarm() for Windows 2003
  26087 Storable 0.1 compatibility
  25861 IO​::File performace issue
  25084 long groups entry could cause memory exhaustion
  24699 ICMP_UNREACHABLE handling in Net​::Ping


@​INC for perl v5.8.8​:
  D​:/share/apps/BuildTools/win32/perl/perl-5.8.8-tmw-022/lib
  D​:/share/apps/BuildTools/win32/perl/perl-5.8.8-tmw-022/site/lib
  .


Environment for perl v5.8.8​:
  HOME (unset)
  LANG (unset)
  LANGUAGE (unset)
  LD_LIBRARY_PATH (unset)
  LOGDIR (unset)
  PATH=D​:\share\apps\BuildTools\MKSTK_9.0p2\mksnt;D​:\share\apps\BuildTools\1.2\win32\bin;D​:\share\apps\BuildTools\win32\perl\perl-5.8.8-tmw-022\bin;D​:\win32\apps\gnat\3.15p\bin;S​:\Akernel\matlab\bin;S​:\Akernel\matlab\bin\win32;D​:\share\apps\bat\bat2.8.8.1\win32;D​:\share\apps\bat\bat2.8.8.1\share;C​:\WINNT\System32;C​:\WINNT;C​:\WINNT\System32\Wbem;C​:\Perl\bin;C​:\Applications\Executive Software\DiskeeperWorkstation\;C​:\Applications\reskit;C​:\Program Files\Microsoft Visual Studio .NET 2003\Common7\Tools;C​:\Applications\Microsoft Visual Studio\VC98\Bin;C​:\Applications\Microsoft Visual Studio\Common\MSDev98\Bin;\\mathworks\hub\bat\win2000\bin;\\mathworks\hub\bat\nt\bin;C​:\Applications\CA\SharedComponents\ScanEngine;C​:\Applications\CA\SharedComponents\CAUpdate\;C​:\Applications\CA\SharedComponents\ThirdParty\;C​:\Applications\CA\SharedComponents\SubscriptionLicense\;C​:\Applications\CA\eTrustITM
  PERL=C​:\Perl\bin\perl.exe
  PERL_BADLANG (unset)
  SHELL (unset)

@p5pRT
Copy link
Author

p5pRT commented Nov 2, 2007

From Gadi.Reinhorn@mathworks.com

This is an accidental Duplicate of [perl #47115].
Sorry.

Gadi

@p5pRT
Copy link
Author

p5pRT commented Nov 2, 2007

From david@landgren.net

Gadi Reinhorn wrote​:

This is an accidental Duplicate of [perl #47115].

I saw that. I have merged this ticket into #47115

Sorry.

No problems. Now to understand and fix the bug. 0x5c is backslash if I
remember my ascii...

Gadi

@p5pRT
Copy link
Author

p5pRT commented Nov 2, 2007

The RT System itself - Status changed from 'new' to 'open'

@p5pRT
Copy link
Author

p5pRT commented Nov 2, 2007

From @jandubois

On Fri, 02 Nov 2007, David Landgren wrote​:

Gadi Reinhorn wrote​:

This is an accidental Duplicate of [perl #47115].

I saw that. I have merged this ticket into #47115

Sorry.

No problems. Now to understand and fix the bug. 0x5c is backslash if I
remember my ascii...

It is. It is also the Yen sign or the Won sign in certain Japanese and
Korean code pages...

But the problem here is that Shift-JIS is a variable length encoding, and
0x5c can appear as the second byte in a multi-byte encoding, in which
case it is not a path separator.

I don't think you can do much about it though, as you don't know the
encoding of the argument to rmtree().

Cheers,
-Jan

@p5pRT
Copy link
Author

p5pRT commented Nov 3, 2007

From Gadi.Reinhorn@mathworks.com

Jan,

You are right about the nature of the Shift-JIS encoding. Yet, the
problem is not with the input to rmtree. In my example, the input does
not have Shift-JIS characters. The problem is that I am IN a directory
with Shift-JIS. Inside rmtree getcwd is called. That is returning the
result in the wrong form.

I'm not sure how to handle this, but I didn't see getcwd on the list of
functions known not to handle Unicode.

http​://search.cpan.org/~nwclark/perl-5.8.8/pod/perlunicode.pod#When_Unic
ode_Does_Not_Happen

When I replace getcwd with a system call to PWD, my program works.

I'm going to work around this by not calling rmtree, but it would be
nice if that worked. I don't know enough about working with Unicode to
suggest a fix, but I hope there is a way to getcwd properly.

Thanks for looking into this.

Gadi

-----Original Message-----
From​: Jan Dubois [mailto​:jand@​activestate.com]
Sent​: Friday, November 02, 2007 7​:49 PM
To​: 'David Landgren'; Gadi Reinhorn
Cc​: perlbug-followup@​perl.org
Subject​: RE​: [perl #47117] perlbug AutoReply​: rmtree can not be called
from a directory with a SJIS character with trailing 0x5c in path.

On Fri, 02 Nov 2007, David Landgren wrote​:

Gadi Reinhorn wrote​:

This is an accidental Duplicate of [perl #47115].

I saw that. I have merged this ticket into #47115

Sorry.

No problems. Now to understand and fix the bug. 0x5c is backslash if I
remember my ascii...

It is. It is also the Yen sign or the Won sign in certain Japanese and
Korean code pages...

But the problem here is that Shift-JIS is a variable length encoding,
and
0x5c can appear as the second byte in a multi-byte encoding, in which
case it is not a path separator.

I don't think you can do much about it though, as you don't know the
encoding of the argument to rmtree().

Cheers,
-Jan

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants