qt5base-lts/tests/auto/corelib/io
Marc Mutz 4bc85b9850 QBuffer: fail early in seek() beyond QByteArray's max capacity
On 32-bit platforms, the range of qsizetype is smaller than the range
of the qint64 used as a parameter in seek().

When seek()ing beyond the current buffer's size, the old code relied
on a write() to fill the gap with NUL bytes. This has two problems:

First, this may allocate a huge amount of memory just to find that it
cannot write that much, possibly even taking the program down when the
allocation in the QByteArray ctor fails, instead of returning false from
seek().

Second, the QByteArray ctor to which we pass the gapSize only takes
qsizetype, not qint64, so we were writing data of size gapSize mod
(INT_MAX+1) on 32-bit platforms, which may succeed, just to find that
that wasn't the number of bytes we expected to be written. By that
time, however, the internal buffer has already been enlarged.

Fix by checking whether the desired seek position is within the limits
that QByteArray can contain early on, before attempting to construct
such a large QByteArray.

[ChangeLog][QtCore][QBuffer] Fixed silent data corruption on 32-bit
platforms when seek() fails due to position > INT_MAX.

Pick-to: 6.3 6.2 5.15
Fixes: QTBUG-102274
Change-Id: Ib63cef7e7e61ef8101a5f056c7b2198bb7baa228
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2022-04-05 20:34:44 +00:00
..
largefile QNX: Limit maximum largefile size 2021-12-12 13:12:01 +02:00
qabstractfileengine Remove unused .qrc files 2022-01-17 23:17:01 +01:00
qbuffer QBuffer: fail early in seek() beyond QByteArray's max capacity 2022-04-05 20:34:44 +00:00
qdataurl qDecodeDataUrl(): treat ";base64" marker as case-insensitive 2022-03-11 19:15:49 +00:00
qdebug Remove the qmake project files 2021-01-07 15:32:28 +01:00
qdir Remove unused .qrc files 2022-01-17 23:17:01 +01:00
qdiriterator Tests: Do not depend on transitive includes 2022-03-17 17:14:37 +01:00
qfile Remove unused .qrc files 2022-01-17 23:17:01 +01:00
qfileinfo Add QFileInfo::isAlias() to reflect whether the file is a macOS alias 2022-03-06 18:46:54 +01:00
qfileselector CMake: Add BUILTIN_TESTDATA option to qt_internal_add_test 2022-02-11 21:54:44 +01:00
qfilesystementry CMake: Remove the usage of QT_SOURCE_TREE from tests 2021-07-12 18:56:14 +02:00
qfilesystemmetadata Remove the qmake project files 2021-01-07 15:32:28 +01:00
qfilesystemwatcher QFileSystemWatcher: Blacklist failing tests on macOS arm 2022-03-29 00:39:20 +00:00
qiodevice tst_QIODevice::unget() without network: skip only the affected part 2022-04-01 23:03:58 +02:00
qipaddress Disable security warnings from MSVC in tests 2021-03-17 17:22:00 +01:00
qlockfile Compile autotests for Integrity 2021-09-20 17:29:04 +03:00
qloggingcategory Tests: Do not depend on transitive includes 2022-03-17 17:14:37 +01:00
qloggingregistry Cleanup tests that add test data to resources explicitly 2022-02-11 21:54:44 +01:00
qnodebug Remove the qmake project files 2021-01-07 15:32:28 +01:00
qprocess QProcess/Unix: ensure we don't accidentally execute something from CWD 2022-02-09 11:26:32 -08:00
qprocess-noapplication Remove the qmake project files 2021-01-07 15:32:28 +01:00
qprocessenvironment QProcess: Distinguish between null and empty QProcessEnvironment 2021-11-07 01:53:44 +01:00
qresourceengine tst_qresourceengine: use QFINDTESTDATA() to find correct path 2022-02-04 11:02:07 +02:00
qsavefile QtBase: replace windows.h with qt_windows.h 2021-11-23 12:53:46 +08:00
qsettings QSettingsPrivate: fold from/to parameters into the view they bound 2022-03-30 21:37:24 +02:00
qstandardpaths Fix autotest public API compilation for INTEGRITY 2021-10-15 11:00:25 +03:00
qstorageinfo Remove the qmake project files 2021-01-07 15:32:28 +01:00
qtemporarydir Enable move semantics for QTemporaryDir 2022-03-18 20:56:19 +00:00
qtemporaryfile Remove unused .qrc files 2022-01-17 23:17:01 +01:00
qurl Workaround MSVC 2022 bug about QString::replace 2021-11-10 14:10:20 +01:00
qurlinternal tst_qurl{,internal}: Use U+FB01 for normalization to ASCII test cases 2021-08-25 00:13:39 +02:00
qurlquery tests: Remove unused SRCDIR defines 2021-08-17 12:41:57 +00:00
qurluts46 Tests: Do not depend on transitive includes 2022-03-17 17:14:37 +01:00
CMakeLists.txt Exclude filesystem autotests for INTEGRITY 2021-12-30 15:38:14 +00:00