Mercurial > cpython-lru_cache-weakref
diff Python/import.c @ 23623:c00febbe0929 2.2
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.
| author | Neal Norwitz <nnorwitz@gmail.com> |
|---|---|
| date | Sat, 01 Jun 2002 18:26:22 +0000 |
| parents | e223397b26fa |
| children | e6cf9557de42 |
line wrap: on
line diff
--- a/Python/import.c Fri May 31 21:17:53 2002 +0000 +++ b/Python/import.c Sat Jun 01 18:26:22 2002 +0000 @@ -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 @@ { 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)
