[ python-Bugs-1776160 ] Buffer overflow when listing deeply nested directory
SourceForge.net
noreply at sourceforge.net
Tue Aug 21 10:18:47 CEST 2007
Bugs item #1776160, was opened at 2007-08-17 13:24
Message generated for change (Comment added) made by loewis
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1776160&group_id=5470
Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Windows
Group: Platform-specific
Status: Open
Resolution: None
Priority: 5
Private: No
Submitted By: Björn Lindqvist (sonderblade)
Assigned to: Nobody/Anonymous (nobody)
Summary: Buffer overflow when listing deeply nested directory
Initial Comment:
This code:
import os
import os.path
TARGET='C:/code/python/foo'
base = TARGET
for x in range(200):
subdirs = os.listdir(base)
base = os.path.join(base, subdirs[0])
print base
Produces a TypeError (buffer overflow) when run on a to deeply nested directory for windows to handle:
.. more output here..
C:code/python/foo\foo bar.png\foo bar.png\foo bar.png\foo bar.png\foo bar.png\foo bar.png\foo bar.png\foo bar.png\foo bar.png\foo bar.png\foo bar.png\foo bar.png\foo bar.p
ng\foo bar.png\foo bar.png\foo bar.png\foo bar.png\foo bar.png\foo bar.png\foo bar.png
Traceback (most recent call last):
File "killdir.py", line 6, in <module>
subdirs = os.listdir(base)
TypeError: listdir() argument 1 must be (buffer overflow), not str
----------------------------------------------------------------------
>Comment By: Martin v. Löwis (loewis)
Date: 2007-08-21 10:18
Message:
Logged In: YES
user_id=21627
Originator: NO
To rephrase Skip's comment: Can you please report what operating system
and Python version you are using?
----------------------------------------------------------------------
Comment By: Skip Montanaro (montanaro)
Date: 2007-08-18 13:38
Message:
Logged In: YES
user_id=44345
Originator: NO
Worked as expected for me on Mac OS X 10.4.10 running from
the trunk (you didn't mention what version you were using).
In ~/tmp/deep I created a maximally nested directory tree from the shell
like so:
cd /Users/skip/tmp/deep
for i in `range 1000` ; do
x=`printf %04d $i`
echo $x
mkdir $x
cd $x
done
where the range command is analogous to Python's range
builtin:
% range 20
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
The for loop barfed after making directory 0205.
In Python I then executed these statements:
import os.path
base = "/Users/skip/tmp/deep"
for x in range(210):
subdirs = os.listdir(base)
base = os.path.join(base, subdirs[0])
print base
This went until it got to dir 0200 where it raised an
OSError:
[Errno 63] File name too long:
'/Users/skip/tmp/deep/0000/0001/.../0199/0200'
which stands to reason since base was 1025 characters long
at that point. MAXPATHLEN is defined to be 1024 on my
system, so the OSError is to be expected.
Skip
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1776160&group_id=5470
More information about the Python-bugs-list
mailing list