]> granicus.if.org Git - python/commitdiff
Issue #11235: Fix OverflowError when trying to import a source file whose modificatio...
authorAntoine Pitrou <solipsis@pitrou.net>
Tue, 24 Jan 2012 16:45:50 +0000 (17:45 +0100)
committerAntoine Pitrou <solipsis@pitrou.net>
Tue, 24 Jan 2012 16:45:50 +0000 (17:45 +0100)
1  2 
Lib/importlib/test/source/test_file_loader.py
Lib/test/test_import.py
Misc/NEWS
Python/import.c

Simple merge
diff --cc Misc/NEWS
index 601bc1949033c86544875f3c1eaa1e6ed4b936a0,5e2c47ee04404af23d2d90e7cc1316c565ccc67d..9c34ac8c1cfbd49c2e94574c0a00d3bd0582a7d3
+++ b/Misc/NEWS
@@@ -10,9 -10,9 +10,12 @@@ What's New in Python 3.3 Alpha 1
  Core and Builtins
  -----------------
  
+ - Issue #11235: Fix OverflowError when trying to import a source file whose
+   modification time doesn't fit in a 32-bit timestamp.
 +- Issue #12705: A SyntaxError exception is now raised when attempting to
 +  compile multiple statements as a single interactive statement.
 +
  - Fix the builtin module initialization code to store the init function for
    future reinitialization.
  
diff --cc Python/import.c
index 76f40d300b5e0ec7eceaf8d31c7e14c5fab44a0d,40b8d0a55835dd75cbf5ac8e790c1aa5ef179c9e..487347ccfbd96905c4876b79e1c9feeb0909faff
@@@ -1478,25 -1304,16 +1478,22 @@@ load_source_module(PyObject *name, PyOb
      }
  #if SIZEOF_TIME_T > 4
      /* Python's .pyc timestamp handling presumes that the timestamp fits
-        in 4 bytes. This will be fine until sometime in the year 2038,
-        when a 4-byte signed time_t will overflow.
+        in 4 bytes. Since the code only does an equality comparison,
+        ordering is not important and we can safely ignore the higher bits
+        (collisions are extremely unlikely).
       */
-     if (st.st_mtime >> 32) {
-         PyErr_SetString(PyExc_OverflowError,
-             "modification time overflows a 4 byte field");
-         goto error;
-     }
+     st.st_mtime &= 0xFFFFFFFF;
  #endif
 -    cpathname = make_compiled_pathname(
 -        pathname, buf, (size_t)MAXPATHLEN + 1, !Py_OptimizeFlag);
 -    if (cpathname != NULL &&
 -        (fpc = check_compiled_module(pathname, st.st_mtime, cpathname))) {
 +    if (PyUnicode_READY(pathname) < 0)
 +        return NULL;
 +    cpathname = make_compiled_pathname(pathname, !Py_OptimizeFlag);
 +
 +    if (cpathname != NULL)
 +        fpc = check_compiled_module(pathname, &st, cpathname);
 +    else
 +        fpc = NULL;
 +
 +    if (fpc) {
          co = read_compiled_module(cpathname, fpc);
          fclose(fpc);
          if (co == NULL)