diff options
| author | Neal Norwitz <nnorwitz@gmail.com> | 2002-06-01 18:26:22 (GMT) |
|---|---|---|
| committer | Neal Norwitz <nnorwitz@gmail.com> | 2002-06-01 18:26:22 (GMT) |
| commit | f79e084e38264e93b78a59df444b1a3dd2b2cf4c (patch) | |
| tree | 0408dbe1c2282614d4f15b08161b6f44e488e236 /Python | |
| parent | 6ad0a79c0705df9eb2a3ddfce187f293497d2ba0 (diff) | |
| download | cpython-f79e084e38264e93b78a59df444b1a3dd2b2cf4c.zip cpython-f79e084e38264e93b78a59df444b1a3dd2b2cf4c.tar.gz cpython-f79e084e38264e93b78a59df444b1a3dd2b2cf4c.tar.bz2 | |
Fix SF #561858 Assertion with very long lists
if co_stacksize was > 32767 (the maximum value
which can be stored in 16 bits (signed)),
the PyCodeObject would be written wrong.
So on the second import (reading the .pyc)
would cause a crash.
Since we can't change the PYC magic, we
go on (silently), but don't write the file.
This means everything will work, but
a .pyc will not be written and the file will need
to be parsed on each import.
I will backport.
Diffstat (limited to 'Python')
| -rw-r--r-- | Python/import.c | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/Python/import.c b/Python/import.c index ba7d5d5..2c2a3a1 100644 --- a/Python/import.c +++ b/Python/import.c @@ -19,6 +19,9 @@ #include <fcntl.h> #endif +/* check if the int_value can't be written in 15 bits (signed) */ +#define CANT_WRITE(int_value) (int_value > 32767) + extern time_t PyOS_GetLastModificationTime(char *, FILE *); /* In getmtime.c */ @@ -687,6 +690,18 @@ write_compiled_module(PyCodeObject *co, char *cpathname, long mtime) { FILE *fp; + if (CANT_WRITE(co->co_argcount) || + CANT_WRITE(co->co_nlocals) || + CANT_WRITE(co->co_stacksize) || + CANT_WRITE(co->co_flags) || + CANT_WRITE(co->co_firstlineno)) { + if (Py_VerboseFlag) + PySys_WriteStderr( + "# code too large: can't write %s\n", + cpathname); + return; + } + fp = open_exclusive(cpathname); if (fp == NULL) { if (Py_VerboseFlag) |
