[issue19636] Fix usage of MAX_PATH in posixmodule.c

2013-12-12 Thread STINNER Victor

Changes by STINNER Victor victor.stin...@gmail.com:


--
resolution:  - fixed
status: open - closed
versions: +Python 3.4

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue19636
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue19636] Fix usage of MAX_PATH in posixmodule.c

2013-11-24 Thread Roundup Robot

Roundup Robot added the comment:

New changeset b3eb42a657a3 by Victor Stinner in branch 'default':
Issue #19636: Fix posix__getvolumepathname(), raise an OverflowError if
http://hg.python.org/cpython/rev/b3eb42a657a3

New changeset 46aecfc5e374 by Victor Stinner in branch 'default':
Issue #19636: Fix usage of MAX_PATH in posixmodule.c
http://hg.python.org/cpython/rev/46aecfc5e374

--
nosy: +python-dev

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue19636
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue19636] Fix usage of MAX_PATH in posixmodule.c

2013-11-19 Thread Tim Golden

Tim Golden added the comment:

Fine with your volumepathname patch. The core of the code was contributed and I 
didn't check it too carefully as it clearly worked. (For some definition of 
worked).

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue19636
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue19636] Fix usage of MAX_PATH in posixmodule.c

2013-11-17 Thread STINNER Victor

New submission from STINNER Victor:

The length of a path is not always correctly handled in posixmodule.c, the 
worst case is posix__getvolumepathname() which pass a length two times smaller 
than the buffer (GetVolumePathNameW() expects a number of WCHAR characters, not 
a number of bytes).

MAX_PATH includes the final null character, so no need to write MAX_PATH+1, 
especially when the function supports path longer than MAX_PATH-1 wide 
characters by allocating a larget buffer.

http://msdn.microsoft.com/en-us/library/aa365247%28VS.85%29.aspx

Maximum Path Length Limitation

In the Windows API (with some exceptions discussed in the following 
paragraphs), the maximum length for a path is MAX_PATH, which is defined as 260 
characters. A local path is structured in the following order: drive letter, 
colon, backslash, name components separated by backslashes, and a terminating 
null character. For example, the maximum path on drive D is D:\some 
256-character path stringNUL where NUL represents the invisible 
terminating null character for the current system codepage. (The characters   
are used here for visual clarity and cannot be part of a valid path string.)

Attached patch fixes usage of MAX_PATH in posixmodule.c.

--
files: win_max_path.patch
keywords: patch
messages: 203231
nosy: haypo
priority: normal
severity: normal
status: open
title: Fix usage of MAX_PATH in posixmodule.c
Added file: http://bugs.python.org/file32675/win_max_path.patch

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue19636
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue19636] Fix usage of MAX_PATH in posixmodule.c

2013-11-17 Thread STINNER Victor

STINNER Victor added the comment:

posix__getfullpathname():

-char outbuf[MAX_PATH*2];
+char outbuf[MAX_PATH];
...
-wchar_t woutbuf[MAX_PATH*2], *woutbufp = woutbuf;
+wchar_t woutbuf[MAX_PATH], *woutbufp = woutbuf;

I don't know what *2 was used here, probably a mistake with 
sizeof(wchar_t)=2? (try to allocate bytes, where the length is a number of wide 
characters)


posix__getvolumepathname() is new in Python 3.4, so not need to backport its 
fix.


path_converter():

 length = PyBytes_GET_SIZE(bytes);
 #ifdef MS_WINDOWS
-if (length  MAX_PATH) {
+if (length  MAX_PATH-1) {
 FORMAT_EXCEPTION(PyExc_ValueError, %s too long for Windows);
 Py_DECREF(bytes);
 return 0;

I don't know if this fix should be backported to Python 3.3.

--
components: +Windows

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue19636
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue19636] Fix usage of MAX_PATH in posixmodule.c

2013-11-17 Thread STINNER Victor

Changes by STINNER Victor victor.stin...@gmail.com:


--
nosy: +tim.golden

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue19636
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue19636] Fix usage of MAX_PATH in posixmodule.c

2013-11-17 Thread STINNER Victor

STINNER Victor added the comment:

Oh, I forgot to mention that my initial concern was the following warning:

  ..\Modules\posixmodule.c(4057): warning C4267: 'function' : conversion from 
'size_t' to 'DWORD', possible loss of data 
[C:\buildbot.python.org\3.x.kloth-win64\build\PCbuild\pythoncore.vcxproj]

bufsize (Py_ssize_t) is passed to GetVolumePathNameW() which expected a DWORD. 
An OverflowError must be raised if bufsize is larger than DWORD_MAX (the 
constant is defined in Modules/_winapi.c, not in posixmodule.c).

But I prefer to fix the warning after this issue.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue19636
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com