diff options
author | João Abecasis <joao@abecasis.name> | 2009-10-28 13:09:04 (GMT) |
---|---|---|
committer | João Abecasis <joao@abecasis.name> | 2009-10-28 13:45:18 (GMT) |
commit | 79da7bb4739f9f63178ce5146702dce6b8feafb9 (patch) | |
tree | 5a885231046f4752e236c2d9663a4fc26cc193ea /src | |
parent | 22b223c31ff961f52f62eaf20aa571b71dfe3bb8 (diff) | |
download | Qt-79da7bb4739f9f63178ce5146702dce6b8feafb9.zip Qt-79da7bb4739f9f63178ce5146702dce6b8feafb9.tar.gz Qt-79da7bb4739f9f63178ce5146702dce6b8feafb9.tar.bz2 |
Don't try to mmap past EOF
On Mac OS, mmap would succeed, returning a valid pointer, but trying to
read from it would result in a SIGBUS.
By adding this check we commit to a safe cross-platform behavior users
can depend on.
Reviewed-by: Thiago Macieira
Diffstat (limited to 'src')
-rw-r--r-- | src/corelib/io/qfsfileengine_unix.cpp | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/src/corelib/io/qfsfileengine_unix.cpp b/src/corelib/io/qfsfileengine_unix.cpp index 6af5674..7824520 100644 --- a/src/corelib/io/qfsfileengine_unix.cpp +++ b/src/corelib/io/qfsfileengine_unix.cpp @@ -1250,6 +1250,12 @@ uchar *QFSFileEnginePrivate::map(qint64 offset, qint64 size, QFile::MemoryMapFla return 0; } + // If we know the mapping will extend beyond EOF, fail early to avoid + // undefined behavior. Otherwise, let mmap have its say. + if (doStat() + && (QT_OFF_T(size) > st.st_size - QT_OFF_T(offset))) + return 0; + int access = 0; if (openMode & QIODevice::ReadOnly) access |= PROT_READ; if (openMode & QIODevice::WriteOnly) access |= PROT_WRITE; |