summaryrefslogtreecommitdiffstats
path: root/third_party/rust/zip/tests/zip_comment_garbage.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:22:09 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:22:09 +0000
commit43a97878ce14b72f0981164f87f2e35e14151312 (patch)
tree620249daf56c0258faa40cbdcf9cfba06de2a846 /third_party/rust/zip/tests/zip_comment_garbage.rs
parentInitial commit. (diff)
downloadfirefox-upstream.tar.xz
firefox-upstream.zip
Adding upstream version 110.0.1.upstream/110.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'third_party/rust/zip/tests/zip_comment_garbage.rs')
-rw-r--r--third_party/rust/zip/tests/zip_comment_garbage.rs30
1 files changed, 30 insertions, 0 deletions
diff --git a/third_party/rust/zip/tests/zip_comment_garbage.rs b/third_party/rust/zip/tests/zip_comment_garbage.rs
new file mode 100644
index 0000000000..ef4d975079
--- /dev/null
+++ b/third_party/rust/zip/tests/zip_comment_garbage.rs
@@ -0,0 +1,30 @@
+// Some zip files can contain garbage after the comment. For example, python zipfile generates
+// it when opening a zip in 'a' mode:
+//
+// >>> from zipfile import ZipFile
+// >>> with ZipFile('comment_garbage.zip', 'a') as z:
+// ... z.comment = b'long comment bla bla bla'
+// ...
+// >>> with ZipFile('comment_garbage.zip', 'a') as z:
+// ... z.comment = b'short.'
+// ...
+// >>>
+//
+// Hexdump:
+//
+// 00000000 50 4b 05 06 00 00 00 00 00 00 00 00 00 00 00 00 |PK..............|
+// 00000010 00 00 00 00 06 00 73 68 6f 72 74 2e 6f 6d 6d 65 |......short.omme|
+// 00000020 6e 74 20 62 6c 61 20 62 6c 61 20 62 6c 61 |nt bla bla bla|
+// 0000002e
+
+use std::io;
+use zip::ZipArchive;
+
+#[test]
+fn correctly_handle_zip_with_garbage_after_comment() {
+ let mut v = Vec::new();
+ v.extend_from_slice(include_bytes!("../tests/data/comment_garbage.zip"));
+ let archive = ZipArchive::new(io::Cursor::new(v)).expect("couldn't open test zip file");
+
+ assert_eq!(archive.comment(), "short.".as_bytes());
+}