summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNeal Norwitz <nnorwitz@gmail.com>2002-06-14 01:07:39 +0000
committerNeal Norwitz <nnorwitz@gmail.com>2002-06-14 01:07:39 +0000
commit7fdcb411312db260e77f291b4e8a865aa61b7c6a (patch)
tree6ebdfc0e3aa5b23ee5ff43ab4dbb99a9c52119d1
parent1f68fc7fa5048e0576ff26436012765f4a8fa3d4 (diff)
downloadcpython-git-7fdcb411312db260e77f291b4e8a865aa61b7c6a.tar.gz
Fix SF bug # 561858 Assertion with very long lists
Write 4 bytes for co_stacksize, etc. to prevent writing out bad .pyc files which can cause a crash when read back in.
-rw-r--r--Lib/test/test_import.py31
-rw-r--r--Python/import.c4
-rw-r--r--Python/marshal.c20
3 files changed, 43 insertions, 12 deletions
diff --git a/Lib/test/test_import.py b/Lib/test/test_import.py
index 933a3645ec..1246822bfa 100644
--- a/Lib/test/test_import.py
+++ b/Lib/test/test_import.py
@@ -3,6 +3,7 @@ from test_support import TESTFN, TestFailed
import os
import random
import sys
+import py_compile
# Brief digression to test that import is case-sensitive: if we got this
# far, we know for sure that "random" exists.
@@ -74,3 +75,33 @@ finally:
import imp
x = imp.find_module("os")
os = imp.load_module("os", *x)
+
+def test_module_with_large_stack(module):
+ # create module w/list of 65000 elements to test bug #561858
+ filename = module + '.py'
+
+ # create a file with a list of 65000 elements
+ f = open(filename, 'w+')
+ f.write('d = [\n')
+ for i in range(65000):
+ f.write('"",\n')
+ f.write(']')
+ f.close()
+
+ # compile & remove .py file, we only need .pyc
+ f = open(filename, 'r')
+ py_compile.compile(filename)
+ os.unlink(filename)
+
+ # need to be able to load from current dir
+ sys.path.append('')
+
+ # this used to crash
+ exec 'import ' + module
+
+ # cleanup
+ del sys.path[-1]
+ os.unlink(module + '.pyc')
+
+test_module_with_large_stack('longlist')
+
diff --git a/Python/import.c b/Python/import.c
index e3efffe773..dabb753077 100644
--- a/Python/import.c
+++ b/Python/import.c
@@ -59,9 +59,9 @@ extern time_t PyOS_GetLastModificationTime(char *, FILE *);
Python 2.1.1: 60202
Python 2.1.2: 60202
Python 2.2: 60717
- Python 2.3a0: 62001
+ Python 2.3a0: 62011
*/
-#define MAGIC (62001 | ((long)'\r'<<16) | ((long)'\n'<<24))
+#define MAGIC (62011 | ((long)'\r'<<16) | ((long)'\n'<<24))
/* Magic word as global; note that _PyImport_Init() can change the
value of this global to accommodate for alterations of how the
diff --git a/Python/marshal.c b/Python/marshal.c
index ab26f51e29..0df46cf163 100644
--- a/Python/marshal.c
+++ b/Python/marshal.c
@@ -241,10 +241,10 @@ w_object(PyObject *v, WFILE *p)
else if (PyCode_Check(v)) {
PyCodeObject *co = (PyCodeObject *)v;
w_byte(TYPE_CODE, p);
- w_short(co->co_argcount, p);
- w_short(co->co_nlocals, p);
- w_short(co->co_stacksize, p);
- w_short(co->co_flags, p);
+ w_long(co->co_argcount, p);
+ w_long(co->co_nlocals, p);
+ w_long(co->co_stacksize, p);
+ w_long(co->co_flags, p);
w_object(co->co_code, p);
w_object(co->co_consts, p);
w_object(co->co_names, p);
@@ -253,7 +253,7 @@ w_object(PyObject *v, WFILE *p)
w_object(co->co_cellvars, p);
w_object(co->co_filename, p);
w_object(co->co_name, p);
- w_short(co->co_firstlineno, p);
+ w_long(co->co_firstlineno, p);
w_object(co->co_lnotab, p);
}
else if (PyObject_CheckReadBuffer(v)) {
@@ -588,10 +588,10 @@ r_object(RFILE *p)
return NULL;
}
else {
- int argcount = r_short(p);
- int nlocals = r_short(p);
- int stacksize = r_short(p);
- int flags = r_short(p);
+ int argcount = r_long(p);
+ int nlocals = r_long(p);
+ int stacksize = r_long(p);
+ int flags = r_long(p);
PyObject *code = NULL;
PyObject *consts = NULL;
PyObject *names = NULL;
@@ -612,7 +612,7 @@ r_object(RFILE *p)
if (cellvars) filename = r_object(p);
if (filename) name = r_object(p);
if (name) {
- firstlineno = r_short(p);
+ firstlineno = r_long(p);
lnotab = r_object(p);
}