1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
use crateZipWriterExtensions;
use cratePreserveSymlinksHandler;
use cratezip_create_from_directory_with_options;
use File;
use PathBuf;
use ZipWriter;
use ZipResult;
use ;
/// Creates a ZIP archive from a directory while preserving symbolic links.
///
/// ### Security Warning
///
/// Preserving symlinks inside ZIP archives can introduce security risks
/// for consumers who inflate the archive using tools or libraries that
/// do **not** validate paths or symlink targets.
///
/// Malicious archives may embed symlinks whose resolved target points
/// outside the intended extraction directory, potentially enabling
/// path traversal or overwriting arbitrary files (“Zip Slip”–style
/// issues).
///
/// This library's own extraction implementation protects against such
/// attacks by sanitizing all paths with `ZipFile::enclosed_name`, and
/// only creating symlinks whose canonicalized target remains inside the
/// extraction root.
///
/// **However, these guarantees do not apply to other extractors.**
/// Developers distributing archives to unknown consumers should prefer
/// [`zip_create_from_directory_with_options`], which resolves symlinks
/// to their pointed-to content instead of preserving them as links.
///
/// ### Recommended use
///
/// - Use this function **only** when you control the extraction
/// environment and know that it properly validates paths and symlinks.
/// - For general distribution or untrusted extraction environments,
/// use `zip_create_from_directory_with_options` instead.