Skip to content

ci(linux): run the tests with AddressSanitizer and UBSan too - #12722

Merged
oc-tmueller merged 4 commits into
masterfrom
ci/linux-asan
Nov 30, 2026
Merged

oc-tmueller merged 4 commits into
masterfrom
ci/linux-asan

Conversation

@oc-tmueller

@oc-tmueller oc-tmueller commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Adds Build and test linux-x86_64-asan as a second entry of the Linux job's matrix, and fixes what it found. The plain entry keeps its name, Build and test linux-x86_64.

The job

  • The client's own code is built with ECM_ENABLE_SANITIZERS='address;undefined' and -O3 -g, against the same Conan archive from ghcr.io; the dependencies aren't instrumented and aren't rebuilt.
  • The whole suite runs with ASAN_OPTIONS=detect_leaks=0:halt_on_error=1 and UBSAN_OPTIONS=print_stacktrace=1:halt_on_error=1. Leak checking is off for now: the tests leak objects (e.g. TestOAuth's accounts), which would need suppressions first.
  • The reports go to files under $RUNNER_TEMP/sanitizers, so those of child processes like test_helper aren't lost; a failed run prints them in the log and uploads them as conan-build-linux-x86_64-asan-sanitizer-reports.
  • vm.mmap_rnd_bits=28: gcc 13's ASan runtime is known to crash at start with the 32 bits of mmap randomization of newer kernels.
  • Timeouts: 120 minutes for the job, 90 for the test step, 900 s per test.
  • The QML format lint runs only in the plain entry.

Linux rather than macOS: locally on macOS, the ASan runtime crashes now and then in the forked child when QProcess starts test_helper, which fails tests that use the helper. The job adds a second Linux run of roughly 1.5 to 2 times the plain one's length; the plain build doesn't change.

What it found

All UBSan, no ASan reports. Each test stopped at its first report, so the later ones only showed up once the earlier ones were fixed:

  1. src/libsync/theme.cpp:170, 24 of 37 tests: qobject_cast<QGuiApplication *>(qApp). With <QGuiApplication> included, qApp is static_cast<QGuiApplication *>(QCoreApplication::instance()), a downcast to a type the object doesn't have in the GUI-less tests (QTEST_GUILESS_MAIN). Every test reaches it through setUpTests() → Logger::setLogFile() → Theme::aboutVersions(). Fixed by QCoreApplication::instance(), also for the same pattern in platform_win.cpp (twice).
  2. src/resources/iconresources.cpp:45, ProtocolModelTest: qGuiApp->styleHints(), the same cast, only to call a static member. Fixed by calling QGuiApplication::styleHints() and QGuiApplication::palette() directly, in iconresources.cpp and resources.cpp.
  3. src/gui/folder.cpp:770, FolderManTest: Folder::wipeForRemoval() called disconnect() on the folder watcher, which a folder only gets once its virtual files plugin has started: a call through a null pointer. Fixed by a check, as the other uses do. fix(gui): don't start the virtual files of a removed folder #12731 fixes the removal of such a folder more broadly and contains the same check, with the same wording.

With these, the whole suite passes under ASan and UBSan. The remaining qApp/qGuiApp uses in src/libsync, src/resources and src/common, which are only correct because of what those files include, are #12730.

Context: the use-after-free in #12716 was found with ASan and isn't visible in normal builds; once its PropagatorTeardownTest is on master, this job catches a regression of it.

🤖 Generated with Claude Code

@update-docs

update-docs Bot commented Nov 25, 2026

Copy link
Copy Markdown

Thanks for opening this pull request! The maintainers of this repository would appreciate it if you would create a changelog item based on your changes.

oc-tmueller and others added 4 commits November 30, 2026 11:15
Add a second entry to the Linux job's matrix that builds the client's
own code with ECM_ENABLE_SANITIZERS=address;undefined, with debug info,
against the same Conan packages, and runs the whole test suite. Leak
checking stays off for now, as the tests leak objects.

The sanitizers write their reports to files, so that those of child
processes such as test_helper aren't lost; a failed test run prints
them and uploads them. The test step times out before the job does, so
a hanging run still gets its logs. The QML format lint runs only in the
plain build.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
qApp is a static_cast of QCoreApplication::instance() to QGuiApplication
or QApplication, depending on which of them is included. Theme's
aboutVersions() and the Windows shutdown watcher used it in qobject_cast
and invokeMethod, which also run in processes with just a
QCoreApplication, such as the tests. That cast is undefined there, and
UBSan reports it in every test that sets up logging. Use
QCoreApplication::instance() instead.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
qGuiApp is a static_cast of QCoreApplication::instance() to
QGuiApplication. isUsingDarkTheme(), buildAvatar() and the icon cache
only used it to call the static styleHints() and palette(), but the cast
is undefined in processes with just a QCoreApplication, e.g. the tests,
which reach isUsingDarkTheme() through getCoreIcon(). UBSan reports it
in ProtocolModelTest.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A folder only gets its folder watcher once its virtual files plugin has
started. wipeForRemoval() called disconnect() on it unconditionally, so
removing a folder before then, e.g. when its account is deleted right
after it was added, called a member function through a null pointer.
UBSan reports it in FolderManTest. Check it, as the other uses do.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@oc-tmueller
oc-tmueller merged commit 91ca6f5 into master Nov 30, 2026
14 checks passed
@oc-tmueller
oc-tmueller deleted the ci/linux-asan branch November 30, 2026 15:59
oc-tmueller added a commit that referenced this pull request Nov 30, 2026
Add a second entry to the Linux job's matrix that builds the client's
own code with ECM_ENABLE_SANITIZERS=address;undefined, with debug info,
against the same Conan packages, and runs the whole test suite. Leak
checking stays off for now, as the tests leak objects. The sanitizers
write their reports to files, which a failed run prints and uploads.

Also don't static_cast a QCoreApplication to the GUI classes through
qApp in Theme::aboutVersions() and the Windows shutdown watcher, which
UBSan reports in every test on master.

Backport of #12722 to 6, which differs from master:
- theme.h includes <qquickwindow.h>, so qApp is a static_cast to
  QGuiApplication in every file that includes it. In logger.cpp, which
  every test reaches through Logger::setLogFile(), and in
  Theme::wizardHeaderTitleColor(), call the static applicationName()
  and palette() through their classes instead.
- There's no src/resources/iconresources.cpp, src/resources/resources.cpp
  has no qGuiApp use, and Folder::wipeForRemoval() resets its
  QScopedPointer folder watcher, which is safe without one, so those
  parts of #12722 don't apply.

(cherry picked from commit 91ca6f5)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
oc-tmueller added a commit that referenced this pull request Nov 30, 2026
…12735)

ci(linux): run the tests with AddressSanitizer and UBSan too (#12722)

* ci(linux): run the tests with AddressSanitizer and UBSan too

Add a second entry to the Linux job's matrix that builds the client's
own code with ECM_ENABLE_SANITIZERS=address;undefined, with debug info,
against the same Conan packages, and runs the whole test suite. Leak
checking stays off for now, as the tests leak objects.

The sanitizers write their reports to files, so that those of child
processes such as test_helper aren't lost; a failed test run prints
them and uploads them. The test step times out before the job does, so
a hanging run still gets its logs. The QML format lint runs only in the
plain build.



* fix(libsync): don't static_cast a QCoreApplication to the GUI classes

qApp is a static_cast of QCoreApplication::instance() to QGuiApplication
or QApplication, depending on which of them is included. Theme's
aboutVersions() and the Windows shutdown watcher used it in qobject_cast
and invokeMethod, which also run in processes with just a
QCoreApplication, such as the tests. That cast is undefined there, and
UBSan reports it in every test that sets up logging. Use
QCoreApplication::instance() instead.



* fix(resources): call QGuiApplication's static members directly

qGuiApp is a static_cast of QCoreApplication::instance() to
QGuiApplication. isUsingDarkTheme(), buildAvatar() and the icon cache
only used it to call the static styleHints() and palette(), but the cast
is undefined in processes with just a QCoreApplication, e.g. the tests,
which reach isUsingDarkTheme() through getCoreIcon(). UBSan reports it
in ProtocolModelTest.



* fix(gui): don't use the folder watcher of a folder that has none yet

A folder only gets its folder watcher once its virtual files plugin has
started. wipeForRemoval() called disconnect() on it unconditionally, so
removing a folder before then, e.g. when its account is deleted right
after it was added, called a member function through a null pointer.
UBSan reports it in FolderManTest. Check it, as the other uses do.



---------



(cherry picked from commit 91ca6f5)

Co-authored-by: Thomas Müller <323649642+oc-tmueller@users.noreply.github.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
oc-tmueller added a commit that referenced this pull request Nov 30, 2026
)

ci(linux): run the tests with AddressSanitizer and UBSan too (#12722)

Add a second entry to the Linux job's matrix that builds the client's
own code with ECM_ENABLE_SANITIZERS=address;undefined, with debug info,
against the same Conan packages, and runs the whole test suite. Leak
checking stays off for now, as the tests leak objects. The sanitizers
write their reports to files, which a failed run prints and uploads.

Also don't static_cast a QCoreApplication to the GUI classes through
qApp in Theme::aboutVersions() and the Windows shutdown watcher, which
UBSan reports in every test on master.

Backport of #12722 to 6, which differs from master:
- theme.h includes <qquickwindow.h>, so qApp is a static_cast to
  QGuiApplication in every file that includes it. In logger.cpp, which
  every test reaches through Logger::setLogFile(), and in
  Theme::wizardHeaderTitleColor(), call the static applicationName()
  and palette() through their classes instead.
- There's no src/resources/iconresources.cpp, src/resources/resources.cpp
  has no qGuiApp use, and Folder::wipeForRemoval() resets its
  QScopedPointer folder watcher, which is safe without one, so those
  parts of #12722 don't apply.

(cherry picked from commit 91ca6f5)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants