summaryrefslogtreecommitdiff
path: root/y4minput.c
diff options
context:
space:
mode:
authorJames Zern <jzern@google.com>2022-07-26 19:08:40 -0700
committerJames Zern <jzern@google.com>2022-07-27 15:37:06 -0700
commit1c0c4d51b474585d05b36d2d70af6b20f507c931 (patch)
tree22bd4c0957d5c3c910f764bda1d22538192a0f71 /y4minput.c
parent9c09d36ee7ac5304c16bc567f3d370c6f96cc7be (diff)
downloadlibvpx-1c0c4d51b474585d05b36d2d70af6b20f507c931.tar
libvpx-1c0c4d51b474585d05b36d2d70af6b20f507c931.tar.gz
libvpx-1c0c4d51b474585d05b36d2d70af6b20f507c931.tar.bz2
libvpx-1c0c4d51b474585d05b36d2d70af6b20f507c931.zip
y4m_input_fetch_frame: fix ubsan null/zero offset warning
reported under clang-13; use a while loop in file_read() to force a size check before attempting to read. buf (aux_buf) may be may be null when no conversion is necessary. y4minput.c:29:43: runtime error: applying zero offset to null pointer Bug: b/229626362 Change-Id: Ia3250d6ff9c325faf48eaa31f4399e20837f8f7b
Diffstat (limited to 'y4minput.c')
-rw-r--r--y4minput.c15
1 files changed, 8 insertions, 7 deletions
diff --git a/y4minput.c b/y4minput.c
index 7d3c03a7f..745e2f1cd 100644
--- a/y4minput.c
+++ b/y4minput.c
@@ -21,12 +21,13 @@
// Reads 'size' bytes from 'file' into 'buf' with some fault tolerance.
// Returns true on success.
static int file_read(void *buf, size_t size, FILE *file) {
- const int kMaxRetries = 5;
- int retry_count = 0;
- int file_error;
+ const int kMaxTries = 5;
+ int try_count = 0;
+ int file_error = 0;
size_t len = 0;
- do {
+ while (!feof(file) && len < size && try_count < kMaxTries) {
const size_t n = fread((uint8_t *)buf + len, 1, size - len, file);
+ ++try_count;
len += n;
file_error = ferror(file);
if (file_error) {
@@ -39,13 +40,13 @@ static int file_read(void *buf, size_t size, FILE *file) {
return 0;
}
}
- } while (!feof(file) && len < size && ++retry_count < kMaxRetries);
+ }
if (!feof(file) && len != size) {
fprintf(stderr,
"Error reading file: %u of %u bytes read,"
- " error: %d, retries: %d, %d: %s\n",
- (uint32_t)len, (uint32_t)size, file_error, retry_count, errno,
+ " error: %d, tries: %d, %d: %s\n",
+ (uint32_t)len, (uint32_t)size, file_error, try_count, errno,
strerror(errno));
}
return len == size;