summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWilliam Wilgus <wilgus.william@gmail.com>2021-07-23 10:06:25 -0400
committerWilliam Wilgus <me.theuser@yahoo.com>2021-07-23 22:53:25 +0000
commit26fd90bb49a5191dc7f4c853e1ec8aa334b5a5c7 (patch)
treea18b4882475e62d750e5464a2e1b478a64ebb0fb
parentcb92280ecad660fa3196f7addea6bd49b0147863 (diff)
downloadrockbox-26fd90bb49.tar.gz
rockbox-26fd90bb49.zip
talk.c check for proper file load
few sanity checks on voice clip loads Change-Id: I15fdf05d2964e9f6d00360b9730357dac6054af7
-rw-r--r--apps/talk.c21
1 files changed, 13 insertions, 8 deletions
diff --git a/apps/talk.c b/apps/talk.c
index 9e92a11b51..73191c22c3 100644
--- a/apps/talk.c
+++ b/apps/talk.c
@@ -377,7 +377,7 @@ static ssize_t read_clip_data(int fd, int index, int clip_handle)
{
struct clip_entry* clipbuf;
size_t clipsize;
- ssize_t ret;
+ ssize_t ret = -1;
if (fd < 0)
{
@@ -388,8 +388,8 @@ static ssize_t read_clip_data(int fd, int index, int clip_handle)
clipbuf = core_get_data(index_handle);
/* this must not be called with LOADED_MASK set in clipsize */
clipsize = clipbuf[index].size;
- lseek(fd, clipbuf[index].offset, SEEK_SET);
- ret = read_to_handle_ex(fd, &clip_ctx, clip_handle, 0, clipsize);
+ if (lseek(fd, clipbuf[index].offset, SEEK_SET) >= 0)
+ ret = read_to_handle_ex(fd, &clip_ctx, clip_handle, 0, clipsize);
if (ret < 0 || clipsize != (size_t)ret)
{
@@ -978,7 +978,8 @@ static int _talk_file(const char* filename,
{
int fd;
int size;
- int handle, oldest = -1;
+ int handle = -1;
+ int oldest = -1;
/* reload needed? */
if (talk_temp_disable_count > 0)
@@ -1005,11 +1006,15 @@ static int _talk_file(const char* filename,
}
size = filesize(fd);
- /* free clips from cache until this one succeeds to allocate */
- while ((handle = buflib_alloc(&clip_ctx, size)) < 0)
- oldest = free_oldest_clip();
+ if (size > 0)
+ {
+ /* free clips from cache until this one succeeds to allocate */
+ while ((handle = buflib_alloc(&clip_ctx, size)) < 0)
+ oldest = free_oldest_clip();
+
+ size = read_to_handle_ex(fd, &clip_ctx, handle, 0, size);
+ }
- size = read_to_handle_ex(fd, &clip_ctx, handle, 0, size);
close(fd);
/* ToDo: find audio, skip ID headers and trailers */