1 """test corrupt file parsing.
11 if not rarfile
.is_rarfile(tmpfn
):
13 rarfile
.RarFile(tmpfn
, errors
="stop")
15 rf
= rarfile
.RarFile(tmpfn
, errors
="strict")
16 if rf
.needs_password():
17 rf
.setpassword("password")
20 for fn
in rf
.namelist():
27 def process_rar(rarfn
, quick
=False):
28 with
open(rarfn
, "rb") as f
:
30 for n
in range(len(data
)):
31 bad
= io
.BytesIO(data
[:n
])
32 if not rarfile
.is_rarfile(bad
):
36 crap
= b
"\x00\xff\x01\x80\x7f"
39 for n
in range(1, len(data
)):
40 for i
in range(len(crap
)):
42 bad
= data
[:n
- 1] + c
+ data
[n
:]
43 try_read(io
.BytesIO(bad
))
46 def test_corrupt_quick_rar3():
47 process_rar("test/files/rar3-comment-plain.rar", True)
50 def test_corrupt_quick_rar5():
51 process_rar("test/files/rar5-times.rar", True)
54 def test_corrupt_all():
55 test_rar_list
= glob
.glob("test/files/*.rar")
57 for rar
in test_rar_list
:
61 if __name__
== "__main__":
62 test_corrupt_quick_rar5()