Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
ec3e20a2
Commit
ec3e20a2
authored
Jun 28, 2019
by
Victor Stinner
Committed by
GitHub
Jun 28, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bpo-37412: Fix os.getcwd() for long path on Windows (GH-14424)
* Fix test for integer overflow. * Add an unit test.
parent
3029035e
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
56 additions
and
1 deletion
+56
-1
Lib/test/test_os.py
Lib/test/test_os.py
+55
-0
Modules/posixmodule.c
Modules/posixmodule.c
+1
-1
No files found.
Lib/test/test_os.py
View file @
ec3e20a2
...
...
@@ -22,6 +22,7 @@ import stat
import
subprocess
import
sys
import
sysconfig
import
tempfile
import
threading
import
time
import
unittest
...
...
@@ -87,6 +88,60 @@ class MiscTests(unittest.TestCase):
cwd
=
os
.
getcwd
()
self
.
assertIsInstance
(
cwd
,
str
)
def
test_getcwd_long_path
(
self
):
# bpo-37412: On Linux, PATH_MAX is usually around 4096 bytes. On
# Windows, MAX_PATH is defined as 260 characters, but Windows supports
# longer path if longer paths support is enabled. Internally, the os
# module uses MAXPATHLEN which is at least 1024.
#
# Use a directory name of 200 characters to fit into Windows MAX_PATH
# limit.
#
# On Windows, the test can stop when trying to create a path longer
# than MAX_PATH if long paths support is disabled:
# see RtlAreLongPathsEnabled().
min_len
=
2000
# characters
dirlen
=
200
# characters
dirname
=
'python_test_dir_'
dirname
=
dirname
+
(
'a'
*
(
dirlen
-
len
(
dirname
)))
with
tempfile
.
TemporaryDirectory
()
as
tmpdir
:
with
support
.
change_cwd
(
tmpdir
):
path
=
tmpdir
expected
=
path
while
True
:
cwd
=
os
.
getcwd
()
self
.
assertEqual
(
cwd
,
expected
)
need
=
min_len
-
(
len
(
cwd
)
+
len
(
os
.
path
.
sep
))
if
need
<=
0
:
break
if
len
(
dirname
)
>
need
and
need
>
0
:
dirname
=
dirname
[:
need
]
path
=
os
.
path
.
join
(
path
,
dirname
)
try
:
os
.
mkdir
(
path
)
# On Windows, chdir() can fail
# even if mkdir() succeeded
os
.
chdir
(
path
)
except
FileNotFoundError
:
# On Windows, catch ERROR_PATH_NOT_FOUND (3) and
# ERROR_FILENAME_EXCED_RANGE (206) errors
# ("The filename or extension is too long")
break
except
OSError
as
exc
:
if
exc
.
errno
==
errno
.
ENAMETOOLONG
:
break
else
:
raise
expected
=
path
if
support
.
verbose
:
print
(
f"Tested current directory length:
{
len
(
cwd
)
}
"
)
def
test_getcwdb
(
self
):
cwd
=
os
.
getcwdb
()
self
.
assertIsInstance
(
cwd
,
bytes
)
...
...
Modules/posixmodule.c
View file @
ec3e20a2
...
...
@@ -3334,7 +3334,7 @@ posix_getcwd(int use_bytes)
terminating \0. If the buffer is too small, len includes
the space needed for the terminator. */
if
(
len
>=
Py_ARRAY_LENGTH
(
wbuf
))
{
if
(
len
>
=
PY_SSIZE_T_MAX
/
sizeof
(
wchar_t
))
{
if
(
len
<
=
PY_SSIZE_T_MAX
/
sizeof
(
wchar_t
))
{
wbuf2
=
PyMem_RawMalloc
(
len
*
sizeof
(
wchar_t
));
}
else
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment