summaryrefslogtreecommitdiff
path: root/Python/marshal.c
diff options
context:
space:
mode:
authorSteve Dower <steve.dower@microsoft.com>2015-02-21 08:44:05 -0800
committerSteve Dower <steve.dower@microsoft.com>2015-02-21 08:44:05 -0800
commitf2f373f5931be48efc3f6fa2c2faa1cca79dce75 (patch)
tree87facdec6423b6282ad5c4e2cf30e124d4a5de40 /Python/marshal.c
parent18d1924987d75ef43a429fe4b6f05df2c308ec2a (diff)
downloadcpython-git-f2f373f5931be48efc3f6fa2c2faa1cca79dce75.tar.gz
Issue #23152: Implement _Py_fstat() to support files larger than 2 GB on Windows.
fstat() may fail with EOVERFLOW on files larger than 2 GB because the file size type is an signed 32-bit integer.
Diffstat (limited to 'Python/marshal.c')
-rw-r--r--Python/marshal.c16
1 files changed, 10 insertions, 6 deletions
diff --git a/Python/marshal.c b/Python/marshal.c
index d26a997534..93d9d1d477 100644
--- a/Python/marshal.c
+++ b/Python/marshal.c
@@ -1481,16 +1481,20 @@ PyMarshal_ReadLongFromFile(FILE *fp)
return res;
}
-#ifdef HAVE_FSTAT
-/* Return size of file in bytes; < 0 if unknown. */
+#if defined(HAVE_FSTAT) || defined(MS_WINDOWS)
+/* Return size of file in bytes; < 0 if unknown or INT_MAX if too big */
static off_t
getfilesize(FILE *fp)
{
- struct stat st;
- if (fstat(fileno(fp), &st) != 0)
+ struct _Py_stat_struct st;
+ if (_Py_fstat(fileno(fp), &st) != 0)
return -1;
+#if SIZEOF_OFF_T == 4
+ else if (st.st_size >= INT_MAX)
+ return (off_t)INT_MAX;
+#endif
else
- return st.st_size;
+ return (off_t)st.st_size;
}
#endif
@@ -1505,7 +1509,7 @@ PyMarshal_ReadLastObjectFromFile(FILE *fp)
{
/* REASONABLE_FILE_LIMIT is by defn something big enough for Tkinter.pyc. */
#define REASONABLE_FILE_LIMIT (1L << 18)
-#ifdef HAVE_FSTAT
+#if defined(HAVE_FSTAT) || defined(MS_WINDOWS)
off_t filesize;
filesize = getfilesize(fp);
if (filesize > 0 && filesize <= REASONABLE_FILE_LIMIT) {