diff --git a/changes/bug21134 b/changes/bug21134 new file mode 100644 index 0000000000..b851718372 --- /dev/null +++ b/changes/bug21134 @@ -0,0 +1,5 @@ + o Minor bugfixes (portability): + - Do not silently truncate content of files if they are larger + than SIZE_MAX bytes. This issue could occur on 32 bit systems + with large file support and files which are larger than 4 GB. + Fixes bug 21134; bugfix on 0.3.0.1-alpha. diff --git a/src/common/compat.c b/src/common/compat.c index ebf05f59e1..16b222904a 100644 --- a/src/common/compat.c +++ b/src/common/compat.c @@ -258,6 +258,12 @@ tor_mmap_file(const char *filename) page_size = getpagesize(); size += (size%page_size) ? page_size-(size%page_size) : 0; + if (st.st_size > SSIZE_T_CEILING || size < st.st_size) { + log_warn(LD_FS, "File \"%s\" is too large. Ignoring.",filename); + errno = EFBIG; + close(fd); + return NULL; + } if (!size) { /* Zero-length file. If we call mmap on it, it will succeed but * return NULL, and bad things will happen. So just fail. */