[bugfix] text_viewer plugin, wonky word wrap, line pos buffer overflow

IpodVT reported odd word wrapping in the case of a perfectly fitting line on a space
which carried over to the next line

in the process I got a ASAN overflow on the line buffer due to
the possibility that lines_per_page - 1 might be -1 and then
reading off in space for an offset into the file
not sure that this would really cause an issue since it would presumably
be bounded within the boundries of the file anyway

Change-Id: Ib5b2c5a30b58faf8bda653f9b9d8d7f76cfb8069
This commit is contained in:
William Wilgus 2026-05-23 18:14:10 -04:00
parent 557694a07f
commit 4ffd098ac9
2 changed files with 14 additions and 5 deletions

View file

@ -318,7 +318,7 @@ void tv_move_screen(int page_offset, int line_offset, int whence)
cur_pos.line = new_pos.line;
if (cur_pos.line >= lines_per_page)
cur_pos.line = lines_per_page - 1;
else if (cur_pos.line < 0)
if (cur_pos.line < 0)
{
cur_pos.line += lines_per_page;
if (cur_pos.line < 0)

View file

@ -362,7 +362,7 @@ static int tv_parse_text(const unsigned char *src, ucschar_t *ucs,
int line_end_chars = 0;
int width = 0;
bool is_space = false;
bool is_align_right = (preferences->alignment == AL_RIGHT);
while (true) {
cur = next;
if (cur >= end_ptr)
@ -410,7 +410,7 @@ static int tv_parse_text(const unsigned char *src, ucschar_t *ucs,
}
/* when the alignment is RIGHT, ignores indent spaces. */
if (preferences->alignment == AL_RIGHT && is_indent)
if (is_align_right && is_indent)
continue;
}
else
@ -427,8 +427,17 @@ static int tv_parse_text(const unsigned char *src, ucschar_t *ucs,
width -= gw;
if (is_space)
{
line_end_ptr = cur;
line_end_chars = chars;
/*Bugfix if not align right leave the space on this line */
if (is_align_right)
{
line_end_ptr = cur;
line_end_chars = chars;
}
else
{
line_end_ptr = next;
line_end_chars = ++chars;
}
}
is_break_line = true;
break;