u32 sector_bytes_left;
        u32 orig_out;
        struct page *cur_page;
 +      char *kaddr;
  
+       if ((*cur_out / PAGE_SIZE) >= max_nr_page)
+               return -E2BIG;
+ 
        /*
         * We never allow a segment header crossing sector boundary, previous
         * run should ensure we have enough space left inside the sector.
                u32 copy_len = min_t(u32, sectorsize - *cur_out % sectorsize,
                                     orig_out + compressed_size - *cur_out);
  
 +              kunmap(cur_page);
++
+               if ((*cur_out / PAGE_SIZE) >= max_nr_page)
+                       return -E2BIG;
+ 
                cur_page = out_pages[*cur_out / PAGE_SIZE];
                /* Allocate a new page */
                if (!cur_page) {
        struct workspace *workspace = list_entry(ws, struct workspace, list);
        const u32 sectorsize = btrfs_sb(mapping->host->i_sb)->sectorsize;
        struct page *page_in = NULL;
 +      char *sizes_ptr;
+       const unsigned long max_nr_page = *out_pages;
        int ret = 0;
        /* Points to the file offset of input data */
        u64 cur_in = start;