Index: Modules/posixmodule.c =================================================================== --- Modules/posixmodule.c (revision 66863) +++ Modules/posixmodule.c (working copy) @@ -2386,20 +2386,34 @@ /* assume encoded strings wont more than double no of chars */ char inbuf[MAX_PATH*2]; char *inbufp = inbuf; - Py_ssize_t insize = sizeof(inbuf); - char outbuf[MAX_PATH*2]; + Py_ssize_t insize = sizeof(inbuf)/sizeof(inbuf[0]); + char outbuf[MAX_PATH+1]; char *temp; + PyObject *v; + DWORD result; #ifdef Py_WIN_WIDE_FILENAMES if (unicode_file_names()) { PyUnicodeObject *po; if (PyArg_ParseTuple(args, "U|:_getfullpathname", &po)) { + Py_UNICODE *wpath = PyUnicode_AS_UNICODE(po); Py_UNICODE woutbuf[MAX_PATH*2]; + Py_UNICODE *woutbufp = woutbuf; Py_UNICODE *wtemp; - if (!GetFullPathNameW(PyUnicode_AS_UNICODE(po), - sizeof(woutbuf)/sizeof(woutbuf[0]), - woutbuf, &wtemp)) - return win32_error("GetFullPathName", ""); - return PyUnicode_FromUnicode(woutbuf, wcslen(woutbuf)); + result = GetFullPathNameW(wpath, sizeof(woutbuf)/sizeof(woutbuf[0]), + woutbuf, &wtemp); + if (result > sizeof(woutbuf)/sizeof(woutbuf[0])) { + woutbufp = malloc(result * sizeof(Py_UNICODE)); + if (!woutbufp) + return PyErr_NoMemory(); + result = GetFullPathNameW(wpath, result, woutbufp, &wtemp); + } + if (!result) + v = win32_error_unicode("GetFullPathName", wpath); + else + v = PyUnicode_FromUnicode(woutbufp, wcslen(woutbufp)); + if (woutbufp != woutbuf) + free(woutbufp); + return v; } /* Drop the argument parsing error as narrow strings are also valid. */ @@ -2410,9 +2424,13 @@ Py_FileSystemDefaultEncoding, &inbufp, &insize)) return NULL; - if (!GetFullPathName(inbuf, sizeof(outbuf)/sizeof(outbuf[0]), - outbuf, &temp)) + result = GetFullPathNameA(inbuf, sizeof(outbuf)/sizeof(outbuf[0]), + outbuf, &temp); + if (!result) return win32_error("GetFullPathName", inbuf); + /* In the ANSI API, there should not be any paths longer + than MAX_PATH. */ + assert(result <= MAX_PATH+1); if (PyUnicode_Check(PyTuple_GetItem(args, 0))) { return PyUnicode_Decode(outbuf, strlen(outbuf), Py_FileSystemDefaultEncoding, NULL);