You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
os.getcwd fails for long path names on linux #46974
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
assignee=Noneclosed_at=<Date2008-06-22.13:37:12.111>created_at=<Date2008-04-30.00:01:51.549>labels= ['easy', 'library']
title='os.getcwd fails for long path names on linux'updated_at=<Date2009-09-02.02:59:47.684>user='https://bugs.python.org/exarkun'
$ python -c "print len('`pwd`'); import os; print os.getcwd()"
1174
Traceback (most recent call last):
File "<string>", line 1, in ?OSError: [Errno 34] Numerical result out of range
$
The getcwd man page documents the ERANGE failure and suggests that the
calling application allocate a larger buffer and try again.
MAX_PATH is a compile time constant which, like FD_BITS for select(),
may be too small for the system you're ultimately running on.
Using that as default initial size is OK, but handling ERANGE is still a
very good idea.
nbm commented on May 10, 2008
nbmmannequin
Mannequin
More actions
This affects OS X too.
I'm attaching two patches - one uses malloc to build a bigger string if
the existing implementation returns ERANGE, and the other one uses
malloc from the start. This was done on the theory that stack memory
use would be better/more efficient. However, based on testing, there's
no real difference - 16.8usec vs. 17usec - on a rarely-used function.
nbm commented on May 10, 2008
nbmmannequin
Mannequin
More actions
Here's a patch to add a test that fails with Python 2.5 on OS X, but
passes with either of these patches.
In my opinion, the fixed length buf should be discarded and instead
allocate memory to buf as needed (as the fix code in posix_getcwd()),
since getcwd() does not have a maximum anymore.
Activity
exarkun commentedon Apr 30, 2008
$ python -c "print len('`pwd`'); import os; print os.getcwd()" 1174 Traceback (most recent call last): File "<string>", line 1, in ? OSError: [Errno 34] Numerical result out of range $The getcwd man page documents the ERANGE failure and suggests that the
calling application allocate a larger buffer and try again.
birkenfeld commentedon Apr 30, 2008
Why isn't the buffer length MAX_PATH anyway?
tiran commentedon Apr 30, 2008
It should be MAX_PATH. All path related functions should use MAX_PATH as
buffer size, maybe even MAX_PATH+1
smurfix commentedon May 7, 2008
MAX_PATH is a compile time constant which, like FD_BITS for select(),
may be too small for the system you're ultimately running on.
Using that as default initial size is OK, but handling ERANGE is still a
very good idea.
nbm commentedon May 10, 2008
This affects OS X too.
I'm attaching two patches - one uses malloc to build a bigger string if
the existing implementation returns ERANGE, and the other one uses
malloc from the start. This was done on the theory that stack memory
use would be better/more efficient. However, based on testing, there's
no real difference - 16.8usec vs. 17usec - on a rarely-used function.
nbm commentedon May 10, 2008
Here's a patch to add a test that fails with Python 2.5 on OS X, but
passes with either of these patches.
facundobatista commentedon Jun 22, 2008
Went for the malloc only patch. Just fixed a small detail (weird corner
case if malloc returned NULL first time, res will be unassigned).
The test could be better (no necessity of using a recursive function, it
could be done with a while), but it works.
Commited in r64452.
boya commentedon Sep 1, 2009
This bug occurred in posix_getcwd() and is being fixed.
Should the following code in posix_getcwdu() also be fixed the same way?
In my opinion, the fixed length buf should be discarded and instead
allocate memory to buf as needed (as the fix code in posix_getcwd()),
since getcwd() does not have a maximum anymore.
amauryfa commentedon Sep 2, 2009
Please open a new issue; and a patch is welcome.
boya commentedon Sep 2, 2009
Amaury,
Created bpo-6817 with a patch.