summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--fs/squashfs/fragment.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/fs/squashfs/fragment.c b/fs/squashfs/fragment.c
index 49602b9a42e1..c46e946fa474 100644
--- a/fs/squashfs/fragment.c
+++ b/fs/squashfs/fragment.c
@@ -69,9 +69,11 @@ __le64 *squashfs_read_fragment_index_table(struct super_block *sb,
/*
* Sanity check, length bytes should not extend into the next table -
* this check also traps instances where fragment_table_start is
- * incorrectly larger than the next table start
+ * incorrectly larger than the next table start. Both values are read
+ * from the filesystem image, so compare without adding them.
*/
- if (fragment_table_start + length > next_table)
+ if (fragment_table_start > next_table ||
+ length > next_table - fragment_table_start)
return ERR_PTR(-EINVAL);
table = squashfs_read_table(sb, fragment_table_start, length);