From: Zhang Yu <zhangyu-f...@cn.fujitsu.com>

[TEST/fuzz] case: 004-simple-dump-tree

Since the wrong key(DATA_RELOC_TREE CHUNK_ITEM 0) in root tree,
error calling print_chunk(), resulting in num_stripes == 0.

ERROR:
     [TEST/fuzz]   004-simple-dump-tree
ctree.h:317: btrfs_chunk_item_size: BUG_ON `num_stripes == 0`
        triggered, value 1

failed (ignored, ret=134): /myproject/btrfs-progs/btrfs
inspect-internal dump-tree
/myproject/btrfs-progs/tests/fuzz-tests/images/
bko-155201-wrong-chunk-item-in-root-tree.raw.restored

test failed for case 004-simple-dump-tree
Makefile:288: recipe for target 'test-fuzz' failed
make: *** [test-fuzz] Error 1

So, check on num_stripes in print_chunk

Signed-off-by: Zhang Yu <zhangyu-f...@cn.fujitsu.com>
---
 print-tree.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/print-tree.c b/print-tree.c
index a0d3395..08f7edb 100644
--- a/print-tree.c
+++ b/print-tree.c
@@ -199,6 +199,15 @@ void print_chunk(struct extent_buffer *eb, struct 
btrfs_chunk *chunk)
 {
        int num_stripes = btrfs_chunk_num_stripes(eb, chunk);
        int i;
+       /*
+        * check on num_stripes
+        * Btrfs_chunk contains at least one stripes
+        */
+       if (num_stripes < 1) {
+               printf("invalid num_stripes: %u\n", num_stripes);
+               return;
+       }
+
        u32 chunk_item_size = btrfs_chunk_item_size(num_stripes);
        char chunk_flags_str[32] = {0};
 
-- 
2.9.4



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