mirror of
https://github.com/python/cpython.git
synced 2025-08-28 04:35:02 +00:00
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.
This commit is contained in:
parent
18d1924987
commit
f2f373f593
12 changed files with 242 additions and 180 deletions
|
@ -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) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue