Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3ddee71

Browse files
committed
New magic word; and check it.
1 parent 75f8968 commit 3ddee71

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

Python/import.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
3737
#include "compile.h"
3838
#include "ceval.h"
3939

40+
/* Magic word to reject pre-0.9.4 .pyc files */
41+
42+
#define MAGIC 0x949494L
43+
4044
/* Define pathname separator used in file names */
4145

4246
#ifdef macintosh
@@ -160,9 +164,10 @@ get_module(m, name, m_ret)
160164
fpc = fopen(namebuf, "rb");
161165
if (fpc != NULL) {
162166
long pyc_mtime;
163-
(void) rd_long(fpc); /* Reserved for magic word */
167+
long magic;
168+
magic = rd_long(fpc);
164169
pyc_mtime = rd_long(fpc);
165-
if (pyc_mtime != 0 && pyc_mtime != -1 && pyc_mtime == mtime) {
170+
if (magic == MAGIC && pyc_mtime == mtime && mtime != 0 && mtime != -1) {
166171
v = rd_object(fpc);
167172
if (v == NULL || err_occurred() || !is_codeobject(v)) {
168173
err_clear();
@@ -202,7 +207,7 @@ get_module(m, name, m_ret)
202207
namebuf[namelen+1] = '\0';
203208
fpc = fopen(namebuf, "wb");
204209
if (fpc != NULL) {
205-
wr_long(0L, fpc); /* Reserved for magic word */
210+
wr_long(MAGIC, fpc);
206211
/* First write a 0 for mtime */
207212
wr_long(0L, fpc);
208213
wr_object((object *)co, fpc);

0 commit comments

Comments
 (0)