Skip to content

fix: overflow when computing scrollbar rect - #6547

Merged
pajlada merged 2 commits into
Chatterino:masterfrom
Nerixyz:fix/scrollbar-overflow
Oct 21, 2025
Merged

pajlada merged 2 commits into
Chatterino:masterfrom
Nerixyz:fix/scrollbar-overflow

Conversation

@Nerixyz

@Nerixyz Nerixyz commented Oct 18, 2025

Copy link
Copy Markdown
Contributor

If maximum <= minimum, then we would divide by 0.0000001. This could result in values for the y-position and height of the scrollbar rectangle that don't fit into a 32-bit signed integer. Consider the following:

  • We're in a search popup without a search - all messages are displayed, we're at the bottom.
  • currentValue_ = 800, pageSize_ = 20, trackHeight_ = 500
  • Now, we're searching something, so the channel gets cleared.
  • During this, maximum_ and minimum_ get set to 0 (while the rest stays as is)
  • Then, calculating the y-position: $\frac{800}{\max(0.0000001, 0)} \cdot 500 + 1 = \frac{800}{0.0000001} \cdot 500 + 1 = 8000000000 \cdot 500 + 1 = 4000000000001 &gt; 2147483648$

The difference between maximum and minimum is the number of messages currently in the channel. With this PR, we assume there's always at least one message when calculating the thumb rect. If there are no messages in a channel, we'll have an incorrect rect, but this won't be shown, because the scrollbar is always hidden in that case.

I updated the documentation of Scrollbar to better indicate the values and meaning of minimum and other members.

@pajlada
pajlada enabled auto-merge (squash) October 21, 2025 15:00
@Wissididom

Copy link
Copy Markdown
Contributor

Changelog: cmputation

@pajlada
pajlada merged commit 346327a into Chatterino:master Oct 21, 2025
19 of 20 checks passed
Pietro228 pushed a commit to Stream-Ally/streamally-chatterino that referenced this pull request Dec 5, 2025
Pietro228 pushed a commit to Stream-Ally/streamally-chatterino that referenced this pull request Dec 5, 2025
babicekmarek pushed a commit to babicekmarek/streamally-chatterino that referenced this pull request Sep 14, 2026
babicekmarek pushed a commit to babicekmarek/streamally-chatterino that referenced this pull request Sep 14, 2026
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.

3 participants