From 914a56f34c590d3872e5c41ce9fff65b637c49b4 Mon Sep 17 00:00:00 2001 From: Roman Artiukhin Date: Tue, 29 Oct 2024 09:40:17 +0200 Subject: imageviewer: fix segfault when album art fails to load Attempt to change file fails due to access to uninitialized memory with negative index Fixup for 55a5bfe7 Change-Id: I9c42f66c856c1d4b7261da5e4996efbe9597bcd4 --- apps/plugins/imageviewer/imageviewer.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/apps/plugins/imageviewer/imageviewer.c b/apps/plugins/imageviewer/imageviewer.c index 77286bd37d..3ae4220721 100644 --- a/apps/plugins/imageviewer/imageviewer.c +++ b/apps/plugins/imageviewer/imageviewer.c @@ -136,15 +136,24 @@ static enum image_type image_type = IMAGE_UNKNOWN; /************************* Implementation ***************************/ /* Read directory contents for scrolling. */ -static void get_pic_list(void) +static void get_pic_list(bool single_file) { + file_pt = (char **) buf; + + if (single_file) + { + file_pt[0] = np_file; + buf_size -= sizeof(file_pt); + entries = 1; + curfile = 0; + return; + } + struct tree_context *tree = rb->tree_get_context(); struct entry *dircache = rb->tree_get_entries(tree); int i; char *pname; - file_pt = (char **) buf; - /* Remove path and leave only the name.*/ pname = rb->strrchr(np_file,'/'); pname++; @@ -1093,7 +1102,6 @@ enum plugin_status plugin_start(const void* parameter) return PLUGIN_ERROR; } - entries = 1; is_album_art = true; } else @@ -1112,11 +1120,7 @@ enum plugin_status plugin_start(const void* parameter) decoder_buf = rb->plugin_get_buffer(&decoder_buf_size); buf = rb->plugin_get_audio_buffer(&buf_size); #endif - - if(!is_album_art) - { - get_pic_list(); - } + get_pic_list(is_album_art); #ifdef USEGSLIB if (!grey_init(buf, buf_size, GREY_ON_COP, -- cgit v1.2.3