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);
