|
|
f63228 |
|
|
|
f63228 |
# HG changeset patch
|
|
|
f63228 |
# User Benjamin Peterson <benjamin@python.org>
|
|
|
f63228 |
# Date 1403579547 25200
|
|
|
f63228 |
# Node ID 8d963c7db507be561e26bbbb852e3a2be3327c3f
|
|
|
f63228 |
# Parent 8e0b7393e921fb5e05c40265f9272dec90512ef6
|
|
|
f63228 |
avoid overflow with large buffer sizes and/or offsets (closes #21831)
|
|
|
f63228 |
|
|
|
f63228 |
diff --git a/Lib/test/test_buffer.py b/Lib/test/test_buffer.py
|
|
|
f63228 |
--- a/Lib/test/test_buffer.py
|
|
|
f63228 |
+++ b/Lib/test/test_buffer.py
|
|
|
f63228 |
@@ -4,6 +4,7 @@ For now, tests just new or changed funct
|
|
|
f63228 |
|
|
|
f63228 |
"""
|
|
|
f63228 |
|
|
|
f63228 |
+import sys
|
|
|
f63228 |
import unittest
|
|
|
f63228 |
from test import test_support
|
|
|
f63228 |
|
|
|
f63228 |
@@ -29,6 +30,11 @@ class BufferTests(unittest.TestCase):
|
|
|
f63228 |
m = memoryview(b) # Should not raise an exception
|
|
|
f63228 |
self.assertEqual(m.tobytes(), s)
|
|
|
f63228 |
|
|
|
f63228 |
+ def test_large_buffer_size_and_offset(self):
|
|
|
f63228 |
+ data = bytearray('hola mundo')
|
|
|
f63228 |
+ buf = buffer(data, sys.maxsize, sys.maxsize)
|
|
|
f63228 |
+ self.assertEqual(buf[:4096], "")
|
|
|
f63228 |
+
|
|
|
f63228 |
|
|
|
f63228 |
def test_main():
|
|
|
f63228 |
with test_support.check_py3k_warnings(("buffer.. not supported",
|
|
|
f63228 |
diff --git a/Objects/bufferobject.c b/Objects/bufferobject.c
|
|
|
f63228 |
--- a/Objects/bufferobject.c
|
|
|
f63228 |
+++ b/Objects/bufferobject.c
|
|
|
f63228 |
@@ -88,7 +88,7 @@ get_buf(PyBufferObject *self, void **ptr
|
|
|
f63228 |
*size = count;
|
|
|
f63228 |
else
|
|
|
f63228 |
*size = self->b_size;
|
|
|
f63228 |
- if (offset + *size > count)
|
|
|
f63228 |
+ if (*size > count - offset)
|
|
|
f63228 |
*size = count - offset;
|
|
|
f63228 |
}
|
|
|
f63228 |
return 1;
|
|
|
f63228 |
@@ -875,4 +875,4 @@ PyTypeObject PyBuffer_Type = {
|
|
|
f63228 |
0, /* tp_init */
|
|
|
f63228 |
0, /* tp_alloc */
|
|
|
f63228 |
buffer_new, /* tp_new */
|
|
|
f63228 |
-};
|
|
|
f63228 |
\ No newline at end of file
|
|
|
f63228 |
+};
|
|
|
f63228 |
|