Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
95bc0e47
Commit
95bc0e47
authored
Sep 30, 2014
by
Benjamin Peterson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
use Py_ssize_t for file offset and length computations in iteration (closes #22526)
parent
ece9d5a9
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
21 additions
and
8 deletions
+21
-8
Lib/test/test_file2k.py
Lib/test/test_file2k.py
+12
-0
Misc/NEWS
Misc/NEWS
+2
-0
Objects/fileobject.c
Objects/fileobject.c
+7
-8
No files found.
Lib/test/test_file2k.py
View file @
95bc0e47
...
...
@@ -436,6 +436,18 @@ class OtherFileTests(unittest.TestCase):
finally
:
f
.
close
()
@
test_support
.
precisionbigmemtest
(
2
**
31
,
1
)
def
test_very_long_line
(
self
,
maxsize
):
# Issue #22526
with
open
(
TESTFN
,
"wb"
)
as
fp
:
fp
.
write
(
"
\
0
"
*
2
**
31
)
with
open
(
TESTFN
,
"rb"
)
as
fp
:
for
l
in
fp
:
pass
self
.
assertEqual
(
len
(
l
),
2
**
31
)
self
.
assertEqual
(
l
.
count
(
"
\
0
"
),
2
**
31
)
l
=
None
class
FileSubclassTests
(
unittest
.
TestCase
):
def
testExit
(
self
):
...
...
Misc/NEWS
View file @
95bc0e47
...
...
@@ -10,6 +10,8 @@ What's New in Python 2.7.9?
Core and Builtins
-----------------
- Issue #22526: Fix iterating through files with lines longer than 2^31 bytes.
- Issue #22519: Fix overflow checking in PyString_Repr.
- Issue #22518: Fix integer overflow issues in latin-1 encoding.
...
...
Objects/fileobject.c
View file @
95bc0e47
...
...
@@ -2236,7 +2236,7 @@ drop_readahead(PyFileObject *f)
(unless at EOF) and no more than bufsize. Returns negative value on
error, will set MemoryError if bufsize bytes cannot be allocated. */
static
int
readahead
(
PyFileObject
*
f
,
in
t
bufsize
)
readahead
(
PyFileObject
*
f
,
Py_ssize_
t
bufsize
)
{
Py_ssize_t
chunksize
;
...
...
@@ -2274,7 +2274,7 @@ readahead(PyFileObject *f, int bufsize)
logarithmic buffer growth to about 50 even when reading a 1gb line. */
static
PyStringObject
*
readahead_get_line_skip
(
PyFileObject
*
f
,
int
skip
,
in
t
bufsize
)
readahead_get_line_skip
(
PyFileObject
*
f
,
Py_ssize_t
skip
,
Py_ssize_
t
bufsize
)
{
PyStringObject
*
s
;
char
*
bufptr
;
...
...
@@ -2294,10 +2294,10 @@ readahead_get_line_skip(PyFileObject *f, int skip, int bufsize)
bufptr
++
;
/* Count the '\n' */
len
=
bufptr
-
f
->
f_bufptr
;
s
=
(
PyStringObject
*
)
PyString_FromStringAndSize
(
NULL
,
skip
+
len
);
PyString_FromStringAndSize
(
NULL
,
skip
+
len
);
if
(
s
==
NULL
)
return
NULL
;
memcpy
(
PyString_AS_STRING
(
s
)
+
skip
,
f
->
f_bufptr
,
len
);
memcpy
(
PyString_AS_STRING
(
s
)
+
skip
,
f
->
f_bufptr
,
len
);
f
->
f_bufptr
=
bufptr
;
if
(
bufptr
==
f
->
f_bufend
)
drop_readahead
(
f
);
...
...
@@ -2305,14 +2305,13 @@ readahead_get_line_skip(PyFileObject *f, int skip, int bufsize)
bufptr
=
f
->
f_bufptr
;
buf
=
f
->
f_buf
;
f
->
f_buf
=
NULL
;
/* Force new readahead buffer */
assert
(
skip
+
len
<
INT_MAX
);
s
=
readahead_get_line_skip
(
f
,
(
int
)(
skip
+
len
),
bufsize
+
(
bufsize
>>
2
)
);
assert
(
len
<=
PY_SSIZE_T_MAX
-
skip
);
s
=
readahead_get_line_skip
(
f
,
skip
+
len
,
bufsize
+
(
bufsize
>>
2
));
if
(
s
==
NULL
)
{
PyMem_Free
(
buf
);
return
NULL
;
}
memcpy
(
PyString_AS_STRING
(
s
)
+
skip
,
bufptr
,
len
);
memcpy
(
PyString_AS_STRING
(
s
)
+
skip
,
bufptr
,
len
);
PyMem_Free
(
buf
);
}
return
s
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment