1 // Some zip files can contain garbage after the comment. For example, python zipfile generates
2 // it when opening a zip in 'a' mode:
3 //
4 // >>> from zipfile import ZipFile
5 // >>> with ZipFile('comment_garbage.zip', 'a') as z:
6 // ...     z.comment = b'long comment bla bla bla'
7 // ...
8 // >>> with ZipFile('comment_garbage.zip', 'a') as z:
9 // ...     z.comment = b'short.'
10 // ...
11 // >>>
12 //
13 // Hexdump:
14 //
15 // 00000000  50 4b 05 06 00 00 00 00  00 00 00 00 00 00 00 00  |PK..............|
16 // 00000010  00 00 00 00 06 00 73 68  6f 72 74 2e 6f 6d 6d 65  |......short.omme|
17 // 00000020  6e 74 20 62 6c 61 20 62  6c 61 20 62 6c 61        |nt bla bla bla|
18 // 0000002e
19 
20 use std::io;
21 use zip::ZipArchive;
22 
23 #[test]
correctly_handle_zip_with_garbage_after_comment()24 fn correctly_handle_zip_with_garbage_after_comment() {
25     let mut v = Vec::new();
26     v.extend_from_slice(include_bytes!("../tests/data/comment_garbage.zip"));
27     let archive = ZipArchive::new(io::Cursor::new(v)).expect("couldn't open test zip file");
28 
29     assert_eq!(archive.comment(), "short.".as_bytes());
30 }
31