From: Neal Norwitz Date: Sat, 1 Jun 2002 18:27:34 +0000 (+0000) Subject: Fix SF #561858 Assertion with very long lists X-Git-Tag: 2.1~36 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=63ab3e2bca1841bb728a558f8bc53218c5635379;p=thirdparty%2FPython%2Fcpython.git 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. --- diff --git a/Python/import.c b/Python/import.c index 3d55fe4c33c3..cdad2022e46c 100644 --- a/Python/import.c +++ b/Python/import.c @@ -32,6 +32,9 @@ #define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR) #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 */ @@ -669,6 +672,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)