10000 Fix cwd length for byte paths & bus error · python/cpython@807b494 · GitHub
[go: up one dir, main page]

Skip to content

Commit 807b494

Browse files
committed
Fix cwd length for byte paths & bus error
1 parent 2475af9 commit 807b494

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

Lib/posixpath.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -406,9 +406,9 @@ def abspath(path):
406406
if path.startswith(b'/'):
407407
return os.fsencode(_path_abspath(os.fsdecode(path)))
408408
else:
409-
cwd = os.getcwdb()
410-
path = join(cwd, path)
411-
return os.fsencode(_path_abspath(os.fsdecode(path), len(cwd)))
409+
cwd = os.fsdecode(os.getcwdb())
410+
path = join(cwd, os.fsdecode(path))
411+
return os.fsencode(_path_abspath(path, len(cwd)))
412412
else:
413413
if path.startswith('/'):
414414
return _path_abspath(path)

Python/fileutils.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2397,6 +2397,11 @@ _Py_normpath_and_size(wchar_t *path, Py_ssize_t size, Py_ssize_t start, Py_ssize
23972397
*normsize = 0;
23982398
return path;
23992399
}
2400+
// Start beyond end of path
2401+
if (start >= size) {
2402+
*normsize = size;
2403+
return path;
2404+
}
24002405
wchar_t *pEnd = size >= 0 ? &path[size] : NULL;
24012406
wchar_t *p1 = path; // sequentially scanned address in the path
24022407
wchar_t *p2 = path; // destination of a scanned character to be ljusted
@@ -2455,11 +2460,11 @@ _Py_normpath_and_size(wchar_t *path, Py_ssize_t size, Py_ssize_t start, Py_ssize
24552460
}
24562461
#endif /* MS_WINDOWS */
24572462

2463+
// Skip past cwd
24582464
if (path + start > p1) {
24592465
p1 = p2 = path + start;
24602466
lastC = *(p1-1);
24612467
}
2462-
24632468
/* if pEnd is specified, check that. Else, check for null terminator */
24642469
for (; !IS_END(p1); ++p1) {
24652470
wchar_t c = *p1;

0 commit comments

Comments
 (0)
0