summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAhmad Samir <a.samirh78@gmail.com>2023-03-08 13:49:21 +0200
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2023-03-14 10:14:09 +0000
commit511254bca93226095663da991192046c9a347bd7 (patch)
treed75a36047f55e01815c73f4960a3a60b308b0ddb
parentf020fa0e91eda02c3d15b6ae27954e0573265a6a (diff)
downloadqtbase-511254bca93226095663da991192046c9a347bd7.tar.gz
QFSFileEngine: fix overflow bug when using lseek64
QT_LSEEK (lseek64()) returns QT_OFF_T, which is off64_t on 32bit systems. The return from the lseek64() call was being assigned to an int, which meant that if the returned value is > INT_MAX it will overflow and the value becomes -1, and since errno would be EOVERFLOW the code would fail to open the file. Fix the issue by assigning the return value to QT_OFF_T. Thanks to Giuseppe for pointing out the issue in the code review. Found by compiling with -Wshorten-64-to-32. [ChangeLog][QtCore][QFile] Fixed a bug where opening a file in append mode may fail if the file size was bigger than INT_MAX. Change-Id: Iad33e3192f37466643a1218d38e5ecc2baaa7dc9 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> (cherry picked from commit 5bffb47d6e45260953bc679e1e9582322064b753) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r--src/corelib/io/qfsfileengine.cpp2
-rw-r--r--src/corelib/io/qfsfileengine_unix.cpp2
2 files changed, 2 insertions, 2 deletions
diff --git a/src/corelib/io/qfsfileengine.cpp b/src/corelib/io/qfsfileengine.cpp
index d924b22431..ffc4878e0d 100644
--- a/src/corelib/io/qfsfileengine.cpp
+++ b/src/corelib/io/qfsfileengine.cpp
@@ -328,7 +328,7 @@ bool QFSFileEnginePrivate::openFd(QIODevice::OpenMode openMode, int fd)
// Seek to the end when in Append mode.
if (openMode & QFile::Append) {
- int ret;
+ QT_OFF_T ret;
do {
ret = QT_LSEEK(fd, 0, SEEK_END);
} while (ret == -1 && errno == EINTR);
diff --git a/src/corelib/io/qfsfileengine_unix.cpp b/src/corelib/io/qfsfileengine_unix.cpp
index a08feb73fb..fb08385c91 100644
--- a/src/corelib/io/qfsfileengine_unix.cpp
+++ b/src/corelib/io/qfsfileengine_unix.cpp
@@ -115,7 +115,7 @@ bool QFSFileEnginePrivate::nativeOpenImpl(QIODevice::OpenMode openMode, mode_t m
// Seek to the end when in Append mode.
if (flags & QFile::Append) {
- int ret;
+ QT_OFF_T ret;
do {
ret = QT_LSEEK(fd, 0, SEEK_END);
} while (ret == -1 && errno == EINTR);