[bugfix] text_viewer plugin, wonky word wrap, line pos buffer overflow
rockbox-gerrit-noreply--- via rockbox-cvs <[email protected]> Sat, 23 May 2026 18:24:01 -0400
| Newsgroups | gmane.comp.systems.archos.rockbox.cvs |
|---|---|
| Message-ID | <[email protected]> |
commit 4ffd098ac92a90106e64ad4a7c5876ee0d57dacb Author: William Wilgus <[email protected]> Date: Sat May 23 18:14:10 2026 -0400 [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 diff --git a/apps/plugins/text_viewer/tv_pager.c b/apps/plugins/text_viewer/tv_pager.c index 628d67f959..66d014f377 100644 --- a/apps/plugins/text_viewer/tv_pager.c +++ b/apps/plugins/text_viewer/tv_pager.c @@ -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) diff --git a/apps/plugins/text_viewer/tv_text_processor.c b/apps/plugins/text_viewer/tv_text_processor.c index 8bc8519780..cf6957fb80 100644 --- a/apps/plugins/text_viewer/tv_text_processor.c +++ b/apps/plugins/text_viewer/tv_text_processor.c @@ -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; -- rockbox-cvs mailing list [email protected] https://lists.haxx.se/mailman/listinfo/rockbox-cvs