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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
use thiserror::Error;
/// Errors that can occur when working with bale archives.
#[derive(Error, Debug)]
pub enum BaleError {
/// I/O error during file operations.
#[error("I/O error: {0}")]
Io(#[from] std::io::Error),
/// Invalid magic signature in archive header.
#[error("invalid signature: expected 0x{expected:08X}, found 0x{found:08X}")]
InvalidSignature {
/// Expected signature value.
expected: u32,
/// Actual signature found.
found: u32,
},
/// Archive path exceeds maximum length.
#[error("path too long: {path:?} exceeds {max} bytes")]
PathTooLong {
/// The path that was too long.
path: String,
/// Maximum allowed path length.
max: usize,
},
/// Invalid alignment value.
#[error("invalid alignment: {0}")]
InvalidAlignment(String),
/// Path size is outside valid range (1-2048).
#[error("invalid path size: {0} is not in range 1..=2048")]
InvalidPathSize(u16),
/// Path is invalid (traversal, empty, or malformed).
#[error("invalid path")]
InvalidPath,
/// Filename contains unsafe characters or patterns.
#[error("unsafe filename: {0}")]
UnsafeFilename(#[from] safename::SafeNameError),
/// Path contains invalid UTF-8.
#[error("invalid UTF-8 in path: {0}")]
InvalidUtf8(#[from] std::str::Utf8Error),
/// Archive is too small to contain a valid trailer.
#[error("archive too small: {size} bytes, minimum is {minimum}")]
TooSmall {
/// Actual size of the archive.
size: u64,
/// Minimum size required.
minimum: u64,
},
/// Entry not found in archive.
#[error("entry not found: {0}")]
EntryNotFound(String),
/// Entry exists but is not a file.
#[error("not a file: {0}")]
NotAFile(String),
/// Entry exists but is not a directory.
#[error("not a directory: {0}")]
NotADirectory(String),
/// Entry exists but is not a symlink.
#[error("not a symlink: {0}")]
NotASymlink(String),
/// Archive data is corrupted or invalid.
#[error("corrupted archive: {0}")]
Corrupted(String),
/// Invalid DOS date/time value.
#[error("invalid DOS date/time: {0}")]
InvalidDosDateTime(String),
/// Size exceeds ZIP format limits.
#[error("size overflow: {0}")]
SizeOverflow(String),
/// Path uses reserved prefix (`.bale`).
#[error("reserved path: {0}")]
ReservedPath(String),
}