summaryrefslogtreecommitdiff
path: root/apps
diff options
context:
space:
mode:
authorWilliam Wilgus <wilgus.william@gmail.com>2021-08-14 20:35:02 -0400
committerWilliam Wilgus <me.theuser@yahoo.com>2021-08-15 11:27:30 +0000
commiteafdba87f8d566d7f66f11e4855d40175853acb0 (patch)
tree3eecbc5ce2c978fe99f943b3e4c07d5102c37374 /apps
parent2ce7c716c3c2e09f881d83b58bdc73cc163962cf (diff)
downloadrockbox-eafdba87f8d566d7f66f11e4855d40175853acb0.tar.gz
rockbox-eafdba87f8d566d7f66f11e4855d40175853acb0.zip
icon.c bug fix handle read errors
read errors are negative buf_sz was a unsignbed int Change-Id: I45ba67e09ce54ff09411248340ba2c9c62c57583
Diffstat (limited to 'apps')
-rw-r--r--apps/gui/icon.c66
1 files changed, 38 insertions, 28 deletions
diff --git a/apps/gui/icon.c b/apps/gui/icon.c
index 46126e830b..9fe7090f4a 100644
--- a/apps/gui/icon.c
+++ b/apps/gui/icon.c
@@ -74,13 +74,13 @@ static struct iconset {
74 (*(inbuilt_iconset[screen])) : iconsets[Iconset_user][screen].bmp).width 74 (*(inbuilt_iconset[screen])) : iconsets[Iconset_user][screen].bmp).width
75 75
76/* x,y in letters, not pixles */ 76/* x,y in letters, not pixles */
77void screen_put_icon(struct screen * display, 77void screen_put_icon(struct screen * display,
78 int x, int y, enum themable_icons icon) 78 int x, int y, enum themable_icons icon)
79{ 79{
80 screen_put_icon_with_offset(display, x, y, 0, 0, icon); 80 screen_put_icon_with_offset(display, x, y, 0, 0, icon);
81} 81}
82 82
83void screen_put_icon_with_offset(struct screen * display, 83void screen_put_icon_with_offset(struct screen * display,
84 int x, int y, int off_x, int off_y, 84 int x, int y, int off_x, int off_y,
85 enum themable_icons icon) 85 enum themable_icons icon)
86{ 86{
@@ -107,7 +107,7 @@ void screen_put_iconxy(struct screen * display,
107 const int height = ICON_HEIGHT(screen); 107 const int height = ICON_HEIGHT(screen);
108 const int is_rtl = lang_is_rtl(); 108 const int is_rtl = lang_is_rtl();
109 const struct bitmap *iconset; 109 const struct bitmap *iconset;
110 110
111 if (icon <= Icon_NOICON) 111 if (icon <= Icon_NOICON)
112 { 112 {
113 if (is_rtl) 113 if (is_rtl)
@@ -119,7 +119,7 @@ void screen_put_iconxy(struct screen * display,
119 { 119 {
120 iconset = &iconsets[Iconset_viewers][screen].bmp; 120 iconset = &iconsets[Iconset_viewers][screen].bmp;
121 icon -= Icon_Last_Themeable; 121 icon -= Icon_Last_Themeable;
122 if (!iconsets[Iconset_viewers][screen].loaded || 122 if (!iconsets[Iconset_viewers][screen].loaded ||
123 (global_status.viewer_icon_count * height > iconset->height) || 123 (global_status.viewer_icon_count * height > iconset->height) ||
124 (icon * height + height > iconset->height)) 124 (icon * height + height > iconset->height))
125 { 125 {
@@ -174,43 +174,54 @@ static struct buflib_callbacks buflib_ops = {buflib_move_callback, NULL, NULL};
174static void load_icons(const char* filename, enum Iconset iconset, 174static void load_icons(const char* filename, enum Iconset iconset,
175 enum screen_type screen) 175 enum screen_type screen)
176{ 176{
177 int size_read; 177 ssize_t size_read;
178 ssize_t buf_size;
179 int fd;
178 int bmpformat = (FORMAT_ANY|FORMAT_DITHER|FORMAT_TRANSPARENT); 180 int bmpformat = (FORMAT_ANY|FORMAT_DITHER|FORMAT_TRANSPARENT);
179 struct iconset *ic = &iconsets[iconset][screen]; 181 struct iconset *ic = &iconsets[iconset][screen];
180 int fd; 182
181
182 ic->loaded = false; 183 ic->loaded = false;
184 ic->handle = 0;
183 if (filename[0] && filename[0] != '-') 185 if (filename[0] && filename[0] != '-')
184 { 186 {
185 char path[MAX_PATH]; 187 char path[MAX_PATH];
186 188
187 snprintf(path, sizeof(path), ICON_DIR "/%s.bmp", filename); 189 snprintf(path, sizeof(path), ICON_DIR "/%s.bmp", filename);
188 fd = open(path, O_RDONLY); 190 fd = open(path, O_RDONLY);
189 if (fd < 0) 191 if (fd < 0)
190 return; 192 return;
191 size_t buf_size = read_bmp_fd(fd, &ic->bmp, 0, 193 buf_size = read_bmp_fd(fd, &ic->bmp, 0,
192 bmpformat|FORMAT_RETURN_SIZE, NULL); 194 bmpformat|FORMAT_RETURN_SIZE, NULL);
193 ic->handle = core_alloc_ex(filename, buf_size, &buflib_ops); 195 if (buf_size > 0)
196 ic->handle = core_alloc_ex(filename, (size_t) buf_size, &buflib_ops);
197
194 if (ic->handle <= 0) 198 if (ic->handle <= 0)
195 { 199 {
196 close(fd); 200 /* error */
197 return; 201 goto finished;
198 } 202 }
199 lseek(fd, 0, SEEK_SET); 203 lseek(fd, 0, SEEK_SET);
200 ic->bmp.data = core_get_data(ic->handle); 204 ic->bmp.data = core_get_data(ic->handle);
201 205
202 ic->handle_locked = 1; 206 ic->handle_locked = 1;
203 size_read = read_bmp_fd(fd, &ic->bmp, buf_size, bmpformat, NULL); 207 size_read = read_bmp_fd(fd, &ic->bmp, buf_size, bmpformat, NULL);
204 close(fd);
205 ic->handle_locked = 0; 208 ic->handle_locked = 0;
206 209
210 if (size_read < 0)
211 {
212 /* error */
213 size_read = 0;
214 }
207 /* free unused alpha channel, if any */ 215 /* free unused alpha channel, if any */
208 core_shrink(ic->handle, ic->bmp.data, size_read > 0 ? size_read : 0); 216 core_shrink(ic->handle, ic->bmp.data, size_read);
209 217
210 if (size_read <= 0) 218 if (size_read == 0)
211 ic->handle = core_free(ic->handle); 219 ic->handle = core_free(ic->handle);
212 else 220 else
213 ic->loaded = true; 221 ic->loaded = true;
222finished:
223 close(fd);
224 return;
214 } 225 }
215} 226}
216 227
@@ -234,31 +245,30 @@ void icons_init(void)
234 { 245 {
235 load_icons(global_settings.icon_file, Iconset_user, SCREEN_MAIN); 246 load_icons(global_settings.icon_file, Iconset_user, SCREEN_MAIN);
236 247
237 if (global_settings.viewers_icon_file[0] && 248 if (global_settings.viewers_icon_file[0] == '-' ||
238 global_settings.viewers_icon_file[0] != '-') 249 global_settings.viewers_icon_file[0] == '\0')
239 { 250 {
240 load_icons(global_settings.viewers_icon_file, 251 load_icons(DEFAULT_VIEWER_BMP, Iconset_viewers, SCREEN_MAIN);
241 Iconset_viewers, SCREEN_MAIN);
242 read_viewer_theme_file();
243 } 252 }
244 else 253 else
245 { 254 {
246 load_icons(DEFAULT_VIEWER_BMP, Iconset_viewers, SCREEN_MAIN); 255 load_icons(global_settings.viewers_icon_file,
256 Iconset_viewers, SCREEN_MAIN);
257 read_viewer_theme_file();
247 } 258 }
248
249#if defined(HAVE_REMOTE_LCD) && (NB_SCREENS > 1) 259#if defined(HAVE_REMOTE_LCD) && (NB_SCREENS > 1)
250 load_icons(global_settings.remote_icon_file, 260 load_icons(global_settings.remote_icon_file,
251 Iconset_user, SCREEN_REMOTE); 261 Iconset_user, SCREEN_REMOTE);
252 262
253 if (global_settings.remote_viewers_icon_file[0] && 263 if (global_settings.remote_viewers_icon_file[0] == '-' ||
254 global_settings.remote_viewers_icon_file[0] != '-') 264 global_settings.remote_viewers_icon_file[0] == '\0')
255 { 265 {
256 load_icons(global_settings.remote_viewers_icon_file, 266 load_icons(DEFAULT_REMOTE_VIEWER_BMP,
257 Iconset_viewers, SCREEN_REMOTE); 267 Iconset_viewers, SCREEN_REMOTE);
258 } 268 }
259 else 269 else
260 { 270 {
261 load_icons(DEFAULT_REMOTE_VIEWER_BMP, 271 load_icons(global_settings.remote_viewers_icon_file,
262 Iconset_viewers, SCREEN_REMOTE); 272 Iconset_viewers, SCREEN_REMOTE);
263 } 273 }
264#endif 274#endif