For inlined extent, we only have one segment, thus less thing to check.
And further more, inlined extent always has csum in its leaf header,
it's less possible to have corrupted data.

Anyway, still check header and segment header.

Signed-off-by: Qu Wenruo <w...@suse.com>
---
 fs/btrfs/lzo.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/fs/btrfs/lzo.c b/fs/btrfs/lzo.c
index 4f4de460b08d..8604f6bc0a29 100644
--- a/fs/btrfs/lzo.c
+++ b/fs/btrfs/lzo.c
@@ -437,15 +437,24 @@ static int lzo_decompress(struct list_head *ws, unsigned 
char *data_in,
        struct workspace *workspace = list_entry(ws, struct workspace, list);
        size_t in_len;
        size_t out_len;
+       size_t max_segment_len = lzo1x_worst_compress(PAGE_SIZE);
        int ret = 0;
        char *kaddr;
        unsigned long bytes;
 
-       BUG_ON(srclen < LZO_LEN);
+       if (srclen < LZO_LEN || srclen > max_segment_len + LZO_LEN * 2)
+               return -EUCLEAN;
 
+       in_len = read_compress_length(data_in);
+       if (in_len != srclen)
+               return -EUCLEAN;
        data_in += LZO_LEN;
 
        in_len = read_compress_length(data_in);
+       if (in_len != srclen - LZO_LEN * 2) {
+               ret = -EUCLEAN;
+               goto out;
+       }
        data_in += LZO_LEN;
 
        out_len = PAGE_SIZE;
-- 
2.17.0

--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to