:: commit f769ce5a01c5377839b7772d05c592418a3eea5d

Mintsuki <mintsuki@protonmail.com> — 2025-12-28 09:17

parents: 3db3f0971a

fs/file: Add bounds check to fread() for memfiles

diff --git a/common/fs/file.s2.c b/common/fs/file.s2.c
index 2fecb9f5..68360667 100644
--- a/common/fs/file.s2.c
+++ b/common/fs/file.s2.c
@@ -83,6 +83,9 @@ void fclose(struct file_handle *fd) {
 
 void fread(struct file_handle *fd, void *buf, uint64_t loc, uint64_t count) {
     if (fd->is_memfile) {
+        if (loc >= fd->size || count > fd->size - loc) {
+            panic(false, "fread: attempted out of bounds read");
+        }
         memcpy(buf, fd->fd + loc, count);
     } else {
         fd->read(fd, buf, loc, count);
tab: 248 wrap: offon