Skip to content

Conversation

nfachan
Copy link
Contributor

@nfachan nfachan commented Aug 13, 2024

If the amount of characters in the screen above the viewport was greater than u16::MAX, a multiplication would overflow. The multiply was used to compute the maximum chunk size. The fix is to just do the multiplication as a usize and also do the subsequent division as a usize.

There is currently another outstanding issue that limits the amount of characters that can be inserted when calling Terminal::insert_before to u16::MAX. However, this bug can still occur even if the viewport and the amount of characters being inserted are both less than u16::MAX, since it's dependant on how large the screen is above the viewport.

Fixes #1322

@nfachan nfachan requested a review from a team as a code owner August 13, 2024 22:43
If the amount of characters in the screen above the viewport was greater
than u16::MAX, a multiplication would overflow. The multiply was used to
compute the maximum chunk size. The fix is to just do the multiplication
as a usize and also do the subsequent division as a usize.

There is currently another outstanding issue that limits the amount of
characters that can be inserted when calling Terminal::insert_before to
u16::MAX. However, this bug can still occur even if the viewport and the
amount of characters being inserted are both less than u16::MAX, since
it's dependant on how large the screen is above the viewport.
@nfachan nfachan changed the title Fix u16 overflow in Terminal::insert_before. fix: fix u16 overflow in Terminal::insert_before. Aug 13, 2024
Copy link

codecov bot commented Aug 13, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 94.3%. Comparing base (0256269) to head (9bc7557).

Additional details and impacted files
@@          Coverage Diff          @@
##            main   #1323   +/-   ##
=====================================
  Coverage   94.3%   94.3%           
=====================================
  Files         66      66           
  Lines      15588   15588           
=====================================
  Hits       14712   14712           
  Misses       876     876           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

github-actions bot commented Aug 13, 2024

🐰Bencher

ReportTue, August 13, 2024 at 23:10:20 UTC
ProjectRatatui
Branch1323/merge
Testbedubuntu-latest

⚠️ WARNING: The following Measure does not have a Threshold. Without a Threshold, no Alerts will ever be generated!

  • Latency (latency)

Click here to create a new Threshold
For more information, see the Threshold documentation.
To only post results if a Threshold exists, set the --ci-only-thresholds CLI flag.

Click to view all benchmark results
BenchmarkLatencyLatency Results
nanoseconds (ns)
barchart/render/2048➖ (view plot)200,900.00
barchart/render/256➖ (view plot)133,940.00
barchart/render/64➖ (view plot)87,277.00
barchart/render_grouped/2048➖ (view plot)346,250.00
barchart/render_grouped/256➖ (view plot)144,070.00
barchart/render_grouped/64➖ (view plot)134,150.00
barchart/render_horizontal/2048➖ (view plot)159,390.00
barchart/render_horizontal/256➖ (view plot)80,173.00
barchart/render_horizontal/64➖ (view plot)73,308.00
block/render_all_feature/100x50➖ (view plot)10,275.00
block/render_all_feature/200x50➖ (view plot)17,838.00
block/render_all_feature/256x256➖ (view plot)83,829.00
block/render_empty/100x50➖ (view plot)5,585.10
block/render_empty/200x50➖ (view plot)10,787.00
block/render_empty/256x256➖ (view plot)70,417.00
buffer/empty/16➖ (view plot)788.09
buffer/empty/255➖ (view plot)226,410.00
buffer/empty/64➖ (view plot)13,460.00
buffer/filled/16➖ (view plot)780.22
buffer/filled/255➖ (view plot)217,400.00
buffer/filled/64➖ (view plot)13,102.00
buffer/with_lines/16➖ (view plot)7,734.00
buffer/with_lines/255➖ (view plot)10,271.00
buffer/with_lines/64➖ (view plot)9,213.00
line_render/Center/0➖ (view plot)3.71
line_render/Center/10➖ (view plot)433.29
line_render/Center/3➖ (view plot)227.07
line_render/Center/4➖ (view plot)253.64
line_render/Center/42➖ (view plot)556.38
line_render/Center/6➖ (view plot)271.32
line_render/Center/7➖ (view plot)304.87
line_render/Left/0➖ (view plot)3.71
line_render/Left/10➖ (view plot)389.44
line_render/Left/3➖ (view plot)155.81
line_render/Left/4➖ (view plot)168.24
line_render/Left/42➖ (view plot)556.40
line_render/Left/6➖ (view plot)260.43
line_render/Left/7➖ (view plot)272.90
line_render/Right/0➖ (view plot)3.72
line_render/Right/10➖ (view plot)390.50
line_render/Right/3➖ (view plot)221.34
line_render/Right/4➖ (view plot)260.18
line_render/Right/42➖ (view plot)556.41
line_render/Right/6➖ (view plot)337.77
line_render/Right/7➖ (view plot)377.74
list/render/16384➖ (view plot)1,151,800.00
list/render/2048➖ (view plot)260,690.00
list/render/64➖ (view plot)139,150.00
list/render_scroll_half/16384➖ (view plot)1,148,000.00
list/render_scroll_half/2048➖ (view plot)265,360.00
list/render_scroll_half/64➖ (view plot)97,179.00
paragraph/new/2048➖ (view plot)251,000.00
paragraph/new/64➖ (view plot)6,629.30
paragraph/new/65535➖ (view plot)7,963,700.00
paragraph/render/2048➖ (view plot)440,020.00
paragraph/render/64➖ (view plot)401,500.00
paragraph/render/65535➖ (view plot)1,512,600.00
paragraph/render_scroll_full/2048➖ (view plot)389,150.00
paragraph/render_scroll_full/64➖ (view plot)424,990.00
paragraph/render_scroll_full/65535➖ (view plot)1,471,800.00
paragraph/render_scroll_half/2048➖ (view plot)390,020.00
paragraph/render_scroll_half/64➖ (view plot)430,710.00
paragraph/render_scroll_half/65535➖ (view plot)1,468,800.00
paragraph/render_wrap/2048➖ (view plot)212,690.00
paragraph/render_wrap/64➖ (view plot)180,190.00
paragraph/render_wrap/65535➖ (view plot)1,365,900.00
paragraph/render_wrap_scroll_full/2048➖ (view plot)212,220.00
paragraph/render_wrap_scroll_full/64➖ (view plot)179,710.00
paragraph/render_wrap_scroll_full/65535➖ (view plot)1,377,800.00
rect_rows/rows/1024➖ (view plot)325.12
rect_rows/rows/16➖ (view plot)5.26
rect_rows/rows/65535➖ (view plot)20,291.00
sparkline/render/2048➖ (view plot)120,430.00
sparkline/render/256➖ (view plot)119,520.00
sparkline/render/64➖ (view plot)38,318.00

Bencher - Continuous Benchmarking
View Public Perf Page
Docs | Repo | Chat | Help

@joshka joshka merged commit 2fb0b8a into ratatui:main Aug 14, 2024
42 of 43 checks passed
@nfachan nfachan deleted the fix-1322 branch August 16, 2024 20:55
joshka pushed a commit to erak/ratatui that referenced this pull request Oct 14, 2024
If the amount of characters in the screen above the viewport was greater
than u16::MAX, a multiplication would overflow. The multiply was used to
compute the maximum chunk size. The fix is to just do the multiplication
as a usize and also do the subsequent division as a usize.

There is currently another outstanding issue that limits the amount of
characters that can be inserted when calling Terminal::insert_before to
u16::MAX. However, this bug can still occur even if the viewport and the
amount of characters being inserted are both less than u16::MAX, since
it's dependant on how large the screen is above the viewport.

Fixes ratatui#1322
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.

Terminal::insert_before has u16 overflow when the screen is very large
2 participants