Skip to content

Fix crashes and instabilities: use-after-free, null derefs, UB, unhandled exceptions#96

Draft
Copilot wants to merge 1 commit intodevelopfrom
copilot/improve-stability-and-reliability
Draft

Fix crashes and instabilities: use-after-free, null derefs, UB, unhandled exceptions#96
Copilot wants to merge 1 commit intodevelopfrom
copilot/improve-stability-and-reliability

Conversation

Copy link
Copy Markdown

Copilot AI commented Apr 15, 2026

Systematic audit of the codebase for crash-causing bugs and undefined behavior. Found and fixed 11 issues across 10 files.

Critical

  • Use-after-free in TracksDirectIORunnable::run() — pointers deleted on load failure, then dereferenced immediately after:
    // Before: delete tracks/tracksPerView, then fall through to:
    aliceVision::track::computeTracksPerView(*tracks, *tracksPerView); // UAF
    // After: early return with resultReady(nullptr, nullptr)
  • Null deref in MSfMData::getUrlFromViewId()_sfmData dereferenced unconditionally

High

  • PhongImageViewer dimension check is a no-opresponseSourceImage.dim != responseSourceImage.dim (compares to self, always false). Fixed to compare against responseNormalImage.dim.
  • Null deref in MSfMData::getViewsIds() — missing _sfmData/status guard
  • Division by zero in FloatImageViewer::updatePaintNode() — zero-height texture or bounding rect
  • Signed integer overflow (UB) in ImageCache::cleanup()INT_MAX + diff; switched to unsigned arithmetic
  • Null deref in FloatTexture::isValid() and setImage()_srcImage never checked
  • throw std::runtime_error from 6 Q_INVOKABLE functions in MViewStats — uncaught exceptions from QML context crash the app. Replaced with qWarning() + early return.
  • Unhandled exception in QtAliceVisionImageIOHandler::read()readImage() can throw

Medium / Low

  • Uninitialized _idView in Surface.hpp — initialized to UndefinedIndexT
  • Unit error in SequenceCache::getRamInfo() — divided by 1024⁴ (TB) instead of 1024³ (GB), reporting cache size 1024× too small

- Fix use-after-free in TracksDirectIORunnable::run() (deleted pointers used after delete)
- Fix logic bug in PhongImageViewer comparing variable to itself instead of other
- Add null checks for _sfmData in MSfMData::getUrlFromViewId() and getViewsIds()
- Guard against division by zero in FloatImageViewer::updatePaintNode()
- Fix signed integer overflow (UB) in ImageCache::cleanup()
- Add null check in FloatTexture::isValid() and setImage()
- Initialize _idView in Surface.hpp to prevent undefined behavior
- Replace throw in Q_INVOKABLE MViewStats functions with qWarning + return
- Add exception handling in QtAliceVisionImageIOHandler::read()
- Fix cache size unit error in SequenceCache::getRamInfo() (TB -> GB)

Agent-Logs-Url: https://github.com/alicevision/QtAliceVision/sessions/4795f35c-99b2-4e57-ab7d-3a42d0b3f9ea

Co-authored-by: fabiencastan <153585+fabiencastan@users.noreply.github.com>
@sonarqubecloud
Copy link
Copy Markdown

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