]>
Commit | Line | Data |
---|---|---|
24342f2c KW |
1 | #!/bin/bash |
2 | # | |
3 | # qcow2 format input validation tests | |
4 | # | |
5 | # Copyright (C) 2013 Red Hat, Inc. | |
6 | # | |
7 | # This program is free software; you can redistribute it and/or modify | |
8 | # it under the terms of the GNU General Public License as published by | |
9 | # the Free Software Foundation; either version 2 of the License, or | |
10 | # (at your option) any later version. | |
11 | # | |
12 | # This program is distributed in the hope that it will be useful, | |
13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | # GNU General Public License for more details. | |
16 | # | |
17 | # You should have received a copy of the GNU General Public License | |
18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | |
19 | # | |
20 | ||
21 | # creator | |
22 | [email protected] | |
23 | ||
24 | seq=`basename $0` | |
25 | echo "QA output created by $seq" | |
26 | ||
27 | here=`pwd` | |
28 | tmp=/tmp/$$ | |
29 | status=1 # failure is the default! | |
30 | ||
31 | _cleanup() | |
32 | { | |
6a83f8b5 KW |
33 | rm -f $TEST_IMG.snap |
34 | _cleanup_test_img | |
24342f2c KW |
35 | } |
36 | trap "_cleanup; exit \$status" 0 1 2 3 15 | |
37 | ||
38 | # get standard environment, filters and checks | |
39 | . ./common.rc | |
40 | . ./common.filter | |
41 | ||
42 | _supported_fmt qcow2 | |
c5f7c0af | 43 | _supported_proto file |
24342f2c KW |
44 | _supported_os Linux |
45 | ||
46 | header_size=104 | |
a1b3955c KW |
47 | |
48 | offset_backing_file_offset=8 | |
6d33e8e7 | 49 | offset_backing_file_size=16 |
2d51c32c KW |
50 | offset_l1_size=36 |
51 | offset_l1_table_offset=40 | |
8c7de283 | 52 | offset_refcount_table_offset=48 |
5dab2fad | 53 | offset_refcount_table_clusters=56 |
ce48f2f4 KW |
54 | offset_nb_snapshots=60 |
55 | offset_snapshots_offset=64 | |
24342f2c KW |
56 | offset_header_size=100 |
57 | offset_ext_magic=$header_size | |
58 | offset_ext_size=$((header_size + 4)) | |
59 | ||
b106ad91 KW |
60 | offset_l2_table_0=$((0x40000)) |
61 | ||
6a83f8b5 KW |
62 | offset_snap1=$((0x70000)) |
63 | offset_snap1_l1_offset=$((offset_snap1 + 0)) | |
64 | offset_snap1_l1_size=$((offset_snap1 + 8)) | |
65 | ||
24342f2c KW |
66 | echo |
67 | echo "== Huge header size ==" | |
68 | _make_test_img 64M | |
69 | poke_file "$TEST_IMG" "$offset_header_size" "\xff\xff\xff\xff" | |
70 | { $QEMU_IO -c "read 0 512" $TEST_IMG; } 2>&1 | _filter_qemu_io | _filter_testdir | |
71 | poke_file "$TEST_IMG" "$offset_header_size" "\x7f\xff\xff\xff" | |
72 | { $QEMU_IO -c "read 0 512" $TEST_IMG; } 2>&1 | _filter_qemu_io | _filter_testdir | |
73 | ||
a1b3955c KW |
74 | echo |
75 | echo "== Huge unknown header extension ==" | |
76 | _make_test_img 64M | |
77 | poke_file "$TEST_IMG" "$offset_backing_file_offset" "\xff\xff\xff\xff\xff\xff\xff\xff" | |
78 | poke_file "$TEST_IMG" "$offset_ext_magic" "\x12\x34\x56\x78" | |
79 | poke_file "$TEST_IMG" "$offset_ext_size" "\x7f\xff\xff\xff" | |
80 | { $QEMU_IO -c "read 0 512" $TEST_IMG; } 2>&1 | _filter_qemu_io | _filter_testdir | |
81 | poke_file "$TEST_IMG" "$offset_backing_file_offset" "\x00\x00\x00\x00\x00\x00\x00\x00" | |
82 | { $QEMU_IO -c "read 0 512" $TEST_IMG; } 2>&1 | _filter_qemu_io | _filter_testdir | |
83 | ||
5dab2fad KW |
84 | echo |
85 | echo "== Huge refcount table size ==" | |
86 | _make_test_img 64M | |
87 | poke_file "$TEST_IMG" "$offset_refcount_table_clusters" "\xff\xff\xff\xff" | |
88 | { $QEMU_IO -c "read 0 512" $TEST_IMG; } 2>&1 | _filter_qemu_io | _filter_testdir | |
89 | poke_file "$TEST_IMG" "$offset_refcount_table_clusters" "\x00\x02\x00\x01" | |
90 | { $QEMU_IO -c "read 0 512" $TEST_IMG; } 2>&1 | _filter_qemu_io | _filter_testdir | |
91 | ||
8c7de283 KW |
92 | echo |
93 | echo "== Misaligned refcount table ==" | |
94 | _make_test_img 64M | |
95 | poke_file "$TEST_IMG" "$offset_refcount_table_offset" "\x12\x34\x56\x78\x90\xab\xcd\xef" | |
96 | { $QEMU_IO -c "read 0 512" $TEST_IMG; } 2>&1 | _filter_qemu_io | _filter_testdir | |
97 | ||
98 | echo | |
99 | echo "== Huge refcount offset ==" | |
100 | _make_test_img 64M | |
101 | poke_file "$TEST_IMG" "$offset_refcount_table_offset" "\xff\xff\xff\xff\xff\xff\x00\x00" | |
102 | poke_file "$TEST_IMG" "$offset_refcount_table_clusters" "\x00\x00\x00\x7f" | |
103 | { $QEMU_IO -c "read 0 512" $TEST_IMG; } 2>&1 | _filter_qemu_io | _filter_testdir | |
5dab2fad | 104 | |
ce48f2f4 KW |
105 | echo |
106 | echo "== Invalid snapshot table ==" | |
107 | _make_test_img 64M | |
108 | poke_file "$TEST_IMG" "$offset_nb_snapshots" "\xff\xff\xff\xff" | |
109 | { $QEMU_IO -c "read 0 512" $TEST_IMG; } 2>&1 | _filter_qemu_io | _filter_testdir | |
110 | poke_file "$TEST_IMG" "$offset_nb_snapshots" "\x7f\xff\xff\xff" | |
111 | { $QEMU_IO -c "read 0 512" $TEST_IMG; } 2>&1 | _filter_qemu_io | _filter_testdir | |
112 | ||
113 | poke_file "$TEST_IMG" "$offset_snapshots_offset" "\xff\xff\xff\xff\xff\xff\x00\x00" | |
114 | poke_file "$TEST_IMG" "$offset_nb_snapshots" "\x00\x00\xff\xff" | |
115 | { $QEMU_IO -c "read 0 512" $TEST_IMG; } 2>&1 | _filter_qemu_io | _filter_testdir | |
116 | ||
117 | poke_file "$TEST_IMG" "$offset_snapshots_offset" "\x12\x34\x56\x78\x90\xab\xcd\xef" | |
118 | poke_file "$TEST_IMG" "$offset_nb_snapshots" "\x00\x00\x00\x00" | |
119 | { $QEMU_IO -c "read 0 512" $TEST_IMG; } 2>&1 | _filter_qemu_io | _filter_testdir | |
120 | ||
121 | echo | |
122 | echo "== Hitting snapshot table size limit ==" | |
123 | _make_test_img 64M | |
124 | # Put the refcount table in a more or less safe place (16 MB) | |
125 | poke_file "$TEST_IMG" "$offset_snapshots_offset" "\x00\x00\x00\x00\x01\x00\x00\x00" | |
126 | poke_file "$TEST_IMG" "$offset_nb_snapshots" "\x00\x01\x00\x00" | |
127 | { $QEMU_IMG snapshot -c test $TEST_IMG; } 2>&1 | _filter_testdir | |
128 | { $QEMU_IO -c "read 0 512" $TEST_IMG; } 2>&1 | _filter_qemu_io | _filter_testdir | |
129 | ||
2d51c32c KW |
130 | echo |
131 | echo "== Invalid L1 table ==" | |
132 | _make_test_img 64M | |
133 | poke_file "$TEST_IMG" "$offset_l1_size" "\xff\xff\xff\xff" | |
134 | { $QEMU_IO -c "read 0 512" $TEST_IMG; } 2>&1 | _filter_qemu_io | _filter_testdir | |
135 | poke_file "$TEST_IMG" "$offset_l1_size" "\x7f\xff\xff\xff" | |
136 | { $QEMU_IO -c "read 0 512" $TEST_IMG; } 2>&1 | _filter_qemu_io | _filter_testdir | |
137 | ||
138 | poke_file "$TEST_IMG" "$offset_l1_table_offset" "\x7f\xff\xff\xff\xff\xff\x00\x00" | |
139 | poke_file "$TEST_IMG" "$offset_l1_size" "\x00\x00\xff\xff" | |
140 | { $QEMU_IO -c "read 0 512" $TEST_IMG; } 2>&1 | _filter_qemu_io | _filter_testdir | |
141 | ||
142 | poke_file "$TEST_IMG" "$offset_l1_table_offset" "\x12\x34\x56\x78\x90\xab\xcd\xef" | |
143 | poke_file "$TEST_IMG" "$offset_l1_size" "\x00\x00\x00\x01" | |
144 | { $QEMU_IO -c "read 0 512" $TEST_IMG; } 2>&1 | _filter_qemu_io | _filter_testdir | |
145 | ||
11b128f4 KW |
146 | echo |
147 | echo "== Invalid L1 table (with internal snapshot in the image) ==" | |
148 | _make_test_img 64M | |
149 | { $QEMU_IMG snapshot -c foo $TEST_IMG; } 2>&1 | _filter_qemu_io | _filter_testdir | |
150 | poke_file "$TEST_IMG" "$offset_l1_size" "\x00\x00\x00\x00" | |
151 | _img_info | |
152 | ||
6d33e8e7 KW |
153 | echo |
154 | echo "== Invalid backing file size ==" | |
155 | _make_test_img 64M | |
156 | poke_file "$TEST_IMG" "$offset_backing_file_offset" "\x00\x00\x00\x00\x00\x00\x10\x00" | |
157 | poke_file "$TEST_IMG" "$offset_backing_file_size" "\xff\xff\xff\xff" | |
158 | { $QEMU_IO -c "read 0 512" $TEST_IMG; } 2>&1 | _filter_qemu_io | _filter_testdir | |
159 | ||
b106ad91 KW |
160 | echo |
161 | echo "== Invalid L2 entry (huge physical offset) ==" | |
162 | _make_test_img 64M | |
163 | { $QEMU_IO -c "write 0 512" $TEST_IMG; } 2>&1 | _filter_qemu_io | _filter_testdir | |
164 | poke_file "$TEST_IMG" "$offset_l2_table_0" "\xbf\xff\xff\xff\xff\xff\x00\x00" | |
165 | { $QEMU_IMG snapshot -c test $TEST_IMG; } 2>&1 | _filter_qemu_io | _filter_testdir | |
166 | poke_file "$TEST_IMG" "$offset_l2_table_0" "\x80\x00\x00\xff\xff\xff\x00\x00" | |
167 | { $QEMU_IMG snapshot -c test $TEST_IMG; } 2>&1 | _filter_qemu_io | _filter_testdir | |
168 | ||
6a83f8b5 KW |
169 | echo |
170 | echo "== Invalid snapshot L1 table ==" | |
171 | _make_test_img 64M | |
172 | { $QEMU_IO -c "write 0 512" $TEST_IMG; } 2>&1 | _filter_qemu_io | _filter_testdir | |
173 | { $QEMU_IMG snapshot -c test $TEST_IMG; } 2>&1 | _filter_testdir | |
174 | poke_file "$TEST_IMG" "$offset_snap1_l1_size" "\x10\x00\x00\x00" | |
175 | { $QEMU_IMG convert -s test $TEST_IMG $TEST_IMG.snap; } 2>&1 | _filter_testdir | |
176 | ||
24342f2c KW |
177 | # success, all done |
178 | echo "*** done" | |
179 | rm -f $seq.full | |
180 | status=0 |