From 9a37772ba8dbb96a4da3ff52a1d7d2fdbb4d8bf2 Mon Sep 17 00:00:00 2001 From: EternalSelf-2328 <71615506+EternalSelf-2328@users.noreply.github.com> Date: Fri, 27 Nov 2026 00:18:17 -0500 Subject: [PATCH] Fix CodeQL arithmetic findings and add continuous integration --- .github/SECURITY.md | 9 +++++++++ .github/workflows/ci.yml | 41 ++++++++++++++++++++++++++++++++++++++++ src/audio.cpp | 3 ++- src/particles.cpp | 7 ++++--- src/perf.cpp | 4 ++-- src/visualizer.cpp | 3 ++- tests/test_particles.cpp | 6 ++++++ 7 files changed, 66 insertions(+), 7 deletions(-) create mode 100644 .github/SECURITY.md create mode 100644 .github/workflows/ci.yml diff --git a/.github/SECURITY.md b/.github/SECURITY.md new file mode 100644 index 0000000..c0f23b5 --- /dev/null +++ b/.github/SECURITY.md @@ -0,0 +1,9 @@ +# Security policy + +Report a suspected vulnerability through [GitHub private vulnerability reporting](https://github.com/EternalSelf-2328/undershell/security/advisories/new). +Include the affected undershell version or commit, your Linux distribution, +the feature involved, and the conditions needed to observe the issue. Remove +credentials and personal paths from logs and attachments before sharing them. + +Use [GitHub Issues](https://github.com/EternalSelf-2328/undershell/issues) for +ordinary bugs and feature requests. diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..2ed20b3 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,41 @@ +name: CI + +on: + push: + branches: [main] + pull_request: + branches: [main] + +permissions: + contents: read + +jobs: + meson: + name: Build and test (Ubuntu 24.04) + runs-on: ubuntu-24.04 + timeout-minutes: 25 + env: + LIBGL_ALWAYS_SOFTWARE: '1' + LP_NUM_THREADS: '2' + steps: + - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0 + with: + persist-credentials: false + - name: Install build and EGL test dependencies + run: | + sudo apt-get update + sudo apt-get install -y --no-install-recommends \ + meson ninja-build pkg-config libwayland-dev wayland-protocols \ + libegl-dev libgles-dev libegl-mesa0 libgl1-mesa-dri libpipewire-0.3-dev \ + libtomlplusplus-dev libglib2.0-dev libcairo2-dev libpango1.0-dev \ + libsqlite3-dev libfontconfig-dev libxkbcommon-dev libsystemd-dev \ + libgdk-pixbuf-2.0-dev libcurl4-openssl-dev nlohmann-json3-dev \ + libavformat-dev libavcodec-dev libswscale-dev libavutil-dev liblz4-dev + - name: Compile + run: | + meson setup build -Dvideo=enabled -Devolution=enabled -Dscenes=enabled + meson compile -C build -j 2 + - name: Run tests with headless EGL + run: | + meson test -C build --no-rebuild --print-errorlogs --num-processes 2 --timeout-multiplier 3 + jq -e -s 'length > 0 and all(.[]; .result == "OK")' build/meson-logs/testlog.json diff --git a/src/audio.cpp b/src/audio.cpp index efdef16..42675e2 100644 --- a/src/audio.cpp +++ b/src/audio.cpp @@ -456,7 +456,8 @@ void Audio::processFrame() { for (size_t i = 0; i < n; ++i) { float v = m_bands[i]; if (v < m_prev[i] && nr > 0.1F) { - v = static_cast(m_peak[i] * (1.0 - m_fall[i] * m_fall[i] * gravityMod)); + const double fall = m_fall[i]; + v = static_cast(m_peak[i] * (1.0 - fall * fall * gravityMod)); v = std::max(v, 0.0F); m_fall[i] += 0.04F; } else { diff --git a/src/particles.cpp b/src/particles.cpp index fa00b38..1fd644e 100644 --- a/src/particles.cpp +++ b/src/particles.cpp @@ -342,8 +342,9 @@ ParticleSystem::ParticleSystem(const ParticleDef& def, const ParticleSettings& s } size_t ParticleSystem::wantedCap() const { - const double n = m_def.max * m_set.amount * perfKnobs().particles; - return std::clamp(static_cast(std::ceil(n)), 1, kMaxCap); + const double n = static_cast(m_def.max) * m_set.amount * perfKnobs().particles; + if (std::isnan(n)) return 1; + return static_cast(std::ceil(std::clamp(n, 1.0, static_cast(kMaxCap)))); } void ParticleSystem::resize(size_t cap) { @@ -700,7 +701,7 @@ void ParticleField::configure(const toml::table& opts, const NoctaliaState& noct auto num = [&](const char* opt, double def, double lo, double hi) { double v = def; if (auto x = opts[particleKey(d.id, opt)].value()) v = *x; - return static_cast(std::clamp(v, lo, hi)); + return static_cast(std::clamp(std::isnan(v) ? def : v, lo, hi)); }; ParticleSettings s; s.amount = num("amount", 1, 0.1, 3); diff --git a/src/perf.cpp b/src/perf.cpp index 56b82bc..f9c7431 100644 --- a/src/perf.cpp +++ b/src/perf.cpp @@ -59,8 +59,8 @@ double PerfGovernor::upCost(PerfLevel level) { if (level == PerfLevel::Ultra) return 1; const PerfKnobs &a = knobsFor(level), &b = knobsFor(step(level, +1)); const double fa = a.fpsCap > 0 ? a.fpsCap : 60, fb = b.fpsCap > 0 ? b.fpsCap : 60; - const double px = (b.renderScale / a.renderScale) * (b.renderScale / a.renderScale); - return std::max(1.0, fb / fa * px); + const double scale = static_cast(b.renderScale) / a.renderScale; + return std::max(1.0, fb / fa * (scale * scale)); } void PerfGovernor::reset(PerfLevel start, PerfLevel floor, PerfLevel ceiling) { diff --git a/src/visualizer.cpp b/src/visualizer.cpp index b35ae50..aa84c01 100644 --- a/src/visualizer.cpp +++ b/src/visualizer.cpp @@ -121,7 +121,8 @@ void Visualizer::configureHalo(const WidgetConfig& cfg, const NoctaliaState& noc BoltRandom r(7); for (size_t i = 0; i < kFilaments; ++i) { m_filAngle[i] = static_cast(i) * 2.39996 + r.range(-0.3F, 0.3F); - m_filSpeed[i] = (r.next() < 0.5F ? -1 : 1) * r.range(0.25F, 0.8F); + const double direction = r.next() < 0.5F ? -1.0 : 1.0; + m_filSpeed[i] = direction * r.range(0.25F, 0.8F); m_filSeed[i] = 101 + static_cast(i) * 7919; } for (size_t k = 0; k < m_arcSeed.size(); ++k) m_arcSeed[k] = 3 + static_cast(k) * 104729; diff --git a/tests/test_particles.cpp b/tests/test_particles.cpp index 7492598..242eade 100644 --- a/tests/test_particles.cpp +++ b/tests/test_particles.cpp @@ -53,6 +53,12 @@ int main() { } CHECK(lib.find("sparks") && lib.find("sparks")->additive && lib.find("sparks")->react > 0); + // A TOML nan uses the option's default and still lets the system emit. + ParticleField normal, nonFinite; + normal.configure(toml::parse("pt_snow = true\n"), testPalette()); + nonFinite.configure(toml::parse("pt_snow = true\npt_snow_amount = nan\n"), testPalette()); + CHECK(normal.count() > 0 && nonFinite.count() == normal.count()); + // what the format refuses CHECK(!parseParticles("x", "{ nope").error.empty()); CHECK(!parseParticles("x", R"({"sprite": "cube"})").error.empty());