4 # qcow2 format input validation tests
6 # Copyright (C) 2013 Red Hat, Inc.
8 # This program is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 2 of the License, or
11 # (at your option) any later version.
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program. If not, see <http://www.gnu.org/licenses/>.
23 owner=kwolf@redhat.com
26 echo "QA output created by $seq"
28 status=1 # failure is the default!
32 _rm_test_img "$TEST_IMG.snap"
35 trap "_cleanup; exit \$status" 0 1 2 3 15
37 # get standard environment, filters and checks
42 _supported_proto file fuse
44 # - Internal snapshots are (currently) impossible with refcount_bits=1,
45 # and generally impossible with external data files
46 # - This is generally a test for compat=1.1 images
47 _unsupported_imgopts 'refcount_bits=1[^0-9]' data_file 'compat=0.10'
51 offset_backing_file_offset=8
52 offset_backing_file_size=16
54 offset_l1_table_offset=40
55 offset_refcount_table_offset=48
56 offset_refcount_table_clusters=56
57 offset_nb_snapshots=60
58 offset_snapshots_offset=64
59 offset_header_size=100
60 offset_ext_magic=$header_size
61 offset_ext_size=$((header_size + 4))
63 offset_l2_table_0=$((0x40000))
65 offset_snap1=$((0x70000))
66 offset_snap1_l1_offset=$((offset_snap1 + 0))
67 offset_snap1_l1_size=$((offset_snap1 + 8))
70 echo "== Huge header size =="
72 poke_file "$TEST_IMG" "$offset_header_size" "\xff\xff\xff\xff"
73 { $QEMU_IO -c "read 0 512" $TEST_IMG; } 2>&1 | _filter_qemu_io | _filter_testdir
74 poke_file "$TEST_IMG" "$offset_header_size" "\x7f\xff\xff\xff"
75 { $QEMU_IO -c "read 0 512" $TEST_IMG; } 2>&1 | _filter_qemu_io | _filter_testdir
78 echo "== Huge unknown header extension =="
80 poke_file "$TEST_IMG" "$offset_backing_file_offset" "\xff\xff\xff\xff\xff\xff\xff\xff"
81 poke_file "$TEST_IMG" "$offset_ext_magic" "\x12\x34\x56\x78"
82 poke_file "$TEST_IMG" "$offset_ext_size" "\x7f\xff\xff\xff"
83 { $QEMU_IO -c "read 0 512" $TEST_IMG; } 2>&1 | _filter_qemu_io | _filter_testdir
84 poke_file "$TEST_IMG" "$offset_backing_file_offset" "\x00\x00\x00\x00\x00\x00\x00\x$(printf %x $offset_ext_size)"
85 { $QEMU_IO -c "read 0 512" $TEST_IMG; } 2>&1 | _filter_qemu_io | _filter_testdir
86 poke_file "$TEST_IMG" "$offset_backing_file_offset" "\x00\x00\x00\x00\x00\x00\x00\x00"
87 { $QEMU_IO -c "read 0 512" $TEST_IMG; } 2>&1 | _filter_qemu_io | _filter_testdir
90 echo "== Huge refcount table size =="
92 poke_file "$TEST_IMG" "$offset_refcount_table_clusters" "\xff\xff\xff\xff"
93 { $QEMU_IO -c "read 0 512" $TEST_IMG; } 2>&1 | _filter_qemu_io | _filter_testdir
94 poke_file "$TEST_IMG" "$offset_refcount_table_clusters" "\x00\x02\x00\x01"
95 { $QEMU_IO -c "read 0 512" $TEST_IMG; } 2>&1 | _filter_qemu_io | _filter_testdir
98 echo "== Misaligned refcount table =="
100 poke_file "$TEST_IMG" "$offset_refcount_table_offset" "\x12\x34\x56\x78\x90\xab\xcd\xef"
101 { $QEMU_IO -c "read 0 512" $TEST_IMG; } 2>&1 | _filter_qemu_io | _filter_testdir
104 echo "== Huge refcount offset =="
106 poke_file "$TEST_IMG" "$offset_refcount_table_offset" "\xff\xff\xff\xff\xff\xff\x00\x00"
107 poke_file "$TEST_IMG" "$offset_refcount_table_clusters" "\x00\x00\x00\x7f"
108 { $QEMU_IO -c "read 0 512" $TEST_IMG; } 2>&1 | _filter_qemu_io | _filter_testdir
111 echo "== Invalid snapshot table =="
113 poke_file "$TEST_IMG" "$offset_nb_snapshots" "\xff\xff\xff\xff"
114 { $QEMU_IO -c "read 0 512" $TEST_IMG; } 2>&1 | _filter_qemu_io | _filter_testdir
115 poke_file "$TEST_IMG" "$offset_nb_snapshots" "\x7f\xff\xff\xff"
116 { $QEMU_IO -c "read 0 512" $TEST_IMG; } 2>&1 | _filter_qemu_io | _filter_testdir
118 poke_file "$TEST_IMG" "$offset_snapshots_offset" "\xff\xff\xff\xff\xff\xff\x00\x00"
119 poke_file "$TEST_IMG" "$offset_nb_snapshots" "\x00\x00\xff\xff"
120 { $QEMU_IO -c "read 0 512" $TEST_IMG; } 2>&1 | _filter_qemu_io | _filter_testdir
122 poke_file "$TEST_IMG" "$offset_snapshots_offset" "\x12\x34\x56\x78\x90\xab\xcd\xef"
123 poke_file "$TEST_IMG" "$offset_nb_snapshots" "\x00\x00\x00\x00"
124 { $QEMU_IO -c "read 0 512" $TEST_IMG; } 2>&1 | _filter_qemu_io | _filter_testdir
127 echo "== Hitting snapshot table size limit =="
129 # Put the refcount table in a more or less safe place (16 MB)
130 poke_file "$TEST_IMG" "$offset_snapshots_offset" "\x00\x00\x00\x00\x01\x00\x00\x00"
131 poke_file "$TEST_IMG" "$offset_nb_snapshots" "\x00\x01\x00\x00"
132 { $QEMU_IMG snapshot -c test $TEST_IMG; } 2>&1 | _filter_testdir
133 { $QEMU_IO -c "read 0 512" $TEST_IMG; } 2>&1 | _filter_qemu_io | _filter_testdir
136 echo "== Invalid L1 table =="
138 poke_file "$TEST_IMG" "$offset_l1_size" "\xff\xff\xff\xff"
139 { $QEMU_IO -c "read 0 512" $TEST_IMG; } 2>&1 | _filter_qemu_io | _filter_testdir
140 poke_file "$TEST_IMG" "$offset_l1_size" "\x7f\xff\xff\xff"
141 { $QEMU_IO -c "read 0 512" $TEST_IMG; } 2>&1 | _filter_qemu_io | _filter_testdir
143 poke_file "$TEST_IMG" "$offset_l1_table_offset" "\x7f\xff\xff\xff\xff\xff\x00\x00"
144 poke_file "$TEST_IMG" "$offset_l1_size" "\x00\x00\xff\xff"
145 { $QEMU_IO -c "read 0 512" $TEST_IMG; } 2>&1 | _filter_qemu_io | _filter_testdir
147 poke_file "$TEST_IMG" "$offset_l1_table_offset" "\x12\x34\x56\x78\x90\xab\xcd\xef"
148 poke_file "$TEST_IMG" "$offset_l1_size" "\x00\x00\x00\x01"
149 { $QEMU_IO -c "read 0 512" $TEST_IMG; } 2>&1 | _filter_qemu_io | _filter_testdir
152 echo "== Invalid L1 table (with internal snapshot in the image) =="
154 { $QEMU_IMG snapshot -c foo $TEST_IMG; } 2>&1 | _filter_qemu_io | _filter_testdir
155 poke_file "$TEST_IMG" "$offset_l1_size" "\x00\x00\x00\x00"
159 echo "== Invalid backing file size =="
161 poke_file "$TEST_IMG" "$offset_backing_file_offset" "\x00\x00\x00\x00\x00\x00\x10\x00"
162 poke_file "$TEST_IMG" "$offset_backing_file_size" "\xff\xff\xff\xff"
163 { $QEMU_IO -c "read 0 512" $TEST_IMG; } 2>&1 | _filter_qemu_io | _filter_testdir
166 echo "== Invalid L2 entry (huge physical offset) =="
168 { $QEMU_IO -c "write 0 512" $TEST_IMG; } 2>&1 | _filter_qemu_io | _filter_testdir
169 poke_file "$TEST_IMG" "$offset_l2_table_0" "\xbf\xff\xff\xff\xff\xff\x00\x00"
170 { $QEMU_IMG snapshot -c test $TEST_IMG; } 2>&1 | _filter_qemu_io | _filter_testdir
171 poke_file "$TEST_IMG" "$offset_l2_table_0" "\x80\x00\x00\xff\xff\xff\x00\x00"
172 { $QEMU_IMG snapshot -c test $TEST_IMG; } 2>&1 | _filter_qemu_io | _filter_testdir
175 echo "== Invalid snapshot L1 table offset =="
177 { $QEMU_IO -c "write 0 512" $TEST_IMG; } 2>&1 | _filter_qemu_io | _filter_testdir
178 { $QEMU_IMG snapshot -c test $TEST_IMG; } 2>&1 | _filter_testdir
179 poke_file "$TEST_IMG" "$offset_snap1_l1_offset" "\x00\x00\x00\x00\x00\x40\x02\x00"
180 { $QEMU_IMG convert -l test $TEST_IMG $TEST_IMG.snap; } 2>&1 | _filter_testdir
181 { $QEMU_IMG amend -o compat=0.10 $TEST_IMG; } 2>&1 | _filter_testdir
182 { $QEMU_IO -c "open -o overlap-check.inactive-l2=on $TEST_IMG" \
183 -c 'write 0 4k'; } 2>&1 | _filter_qemu_io | _filter_testdir
184 { $QEMU_IMG snapshot -a test $TEST_IMG; } 2>&1 | _filter_testdir
185 { $QEMU_IMG snapshot -d test $TEST_IMG; } 2>&1 | _filter_testdir
189 echo "== Invalid snapshot L1 table size =="
191 { $QEMU_IO -c "write 0 512" $TEST_IMG; } 2>&1 | _filter_qemu_io | _filter_testdir
192 { $QEMU_IMG snapshot -c test $TEST_IMG; } 2>&1 | _filter_testdir
193 poke_file "$TEST_IMG" "$offset_snap1_l1_size" "\x10\x00\x00\x00"
194 { $QEMU_IMG convert -l test $TEST_IMG $TEST_IMG.snap; } 2>&1 | _filter_testdir
195 { $QEMU_IMG amend -o compat=0.10 $TEST_IMG; } 2>&1 | _filter_testdir
196 { $QEMU_IO -c "open -o overlap-check.inactive-l2=on $TEST_IMG" \
197 -c 'write 0 4k'; } 2>&1 | _filter_qemu_io | _filter_testdir
198 { $QEMU_IMG snapshot -a test $TEST_IMG; } 2>&1 | _filter_testdir
199 { $QEMU_IMG snapshot -d test $TEST_IMG; } 2>&1 | _filter_testdir