sixel: don’t crash when sixel image exceeds current sixel max height

When we try to resize a sixel past the current max height, we set
col > image-width to signal this.

This means ‘width’ could be smaller than ‘col’. When calculating how
many sixels to emit in sixel_add_many(), we didnt’ account for this.

The resulting value was -1, converted to ‘unsigned’. I.e. a very large
value. This resulted in an assert triggering in sixel_add() in debug
builds, and a crash in release builds.
This commit is contained in:
Daniel Eklöf 2022-10-13 17:52:34 +02:00
parent 3949e34271
commit 43a48f53d4
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F
2 changed files with 2 additions and 1 deletions

View file

@ -88,6 +88,7 @@
built-in terminfo (accessed via XTGETTCAP).
* Crash when interactively resizing the window with a very large
scrollback.
* Crash when a sixel image exceeds the current sixel max height.
[1173]: https://codeberg.org/dnkl/foot/issues/1173

View file

@ -1295,7 +1295,7 @@ sixel_add_many(struct terminal *term, uint8_t c, unsigned count)
if (unlikely(col + count - 1 >= width)) {
resize_horizontally(term, col + count);
width = term->sixel.image.width;
count = min(count, width - col);
count = min(count, max(width - col, 0));
}
uint32_t color = term->sixel.color;