There was an error while loading. Please reload this page.
1 parent 600f3fe commit daafacfCopy full SHA for daafacf
2 files changed
Misc/NEWS.d/next/Security/2025-11-13-22-31-56.gh-issue-42400.pqB5Kq.rst
@@ -0,0 +1,3 @@
1
+Fix buffer overflow in ``_Py_wrealpath()`` for paths exceeding ``MAXPATHLEN`` bytes
2
+by using dynamic memory allocation instead of fixed-size buffer.
3
+Patch by Shamil Abdulaev.
Python/fileutils.c
@@ -2118,7 +2118,6 @@ _Py_wrealpath(const wchar_t *path,
2118
wchar_t *resolved_path, size_t resolved_path_len)
2119
{
2120
char *cpath;
2121
- char cresolved_path[MAXPATHLEN];
2122
wchar_t *wresolved_path;
2123
char *res;
2124
size_t r;
@@ -2127,12 +2126,14 @@ _Py_wrealpath(const wchar_t *path,
2127
2126
errno = EINVAL;
2128
return NULL;
2129
}
2130
- res = realpath(cpath, cresolved_path);
+ res = realpath(cpath, NULL);
2131
PyMem_RawFree(cpath);
2132
if (res == NULL)
2133
2134
2135
- wresolved_path = Py_DecodeLocale(cresolved_path, &r);
+ wresolved_path = Py_DecodeLocale(res, &r);
+ free(res);
2136
+
2137
if (wresolved_path == NULL) {
2138
2139
0 commit comments