Skip to content

Commit 3d70f7a

Browse files
tarkahermo
authored andcommitted
Revert "Revert "stone: Decode unknown variants""
This reverts commit 56e6ebc.
1 parent 56e6ebc commit 3d70f7a

File tree

9 files changed

+132
-90
lines changed

9 files changed

+132
-90
lines changed

crates/stone/src/header/v1.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ const INTEGRITY_CHECK: [u8; 21] = [0, 0, 1, 0, 0, 2, 0, 0, 3, 0, 0, 4, 0, 0, 5,
1111
///
1212
/// Some types are now legacy as we're going to use Ion to define them.
1313
///
14-
#[repr(u8)]
1514
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
15+
#[repr(u8)]
1616
pub enum FileType {
1717
/// Binary package
1818
Binary = 1,
@@ -25,6 +25,8 @@ pub enum FileType {
2525

2626
/// (Legacy) build manifest
2727
BuildManifest,
28+
29+
Unknown = 255,
2830
}
2931

3032
/// Header for the v1 format version
@@ -49,7 +51,7 @@ impl Header {
4951
2 => FileType::Delta,
5052
3 => FileType::Repository,
5153
4 => FileType::BuildManifest,
52-
f => return Err(DecodeError::UnknownFileType(f)),
54+
_ => FileType::Unknown,
5355
};
5456

5557
Ok(Self {
@@ -76,6 +78,4 @@ impl Header {
7678
pub enum DecodeError {
7779
#[error("Corrupt header, failed integrity check")]
7880
Corrupt,
79-
#[error("Unknown file type: {0}")]
80-
UnknownFileType(u8),
8181
}

crates/stone/src/payload/layout.rs

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ use crate::{ReadExt, WriteExt};
1111

1212
/// Layout entries record their target file type so they can be rebuilt on
1313
/// the target installation.
14-
#[repr(u8)]
1514
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
15+
#[repr(u8)]
1616
pub enum FileType {
1717
/// Regular file
1818
Regular = 1,
@@ -34,6 +34,8 @@ pub enum FileType {
3434

3535
/// UNIX Socket
3636
Socket,
37+
38+
Unknown = 255,
3739
}
3840

3941
#[derive(Debug, Clone, PartialEq, Eq)]
@@ -47,6 +49,8 @@ pub enum Entry {
4749
BlockDevice(AStr),
4850
Fifo(AStr),
4951
Socket(AStr),
52+
53+
Unknown(AStr, AStr),
5054
}
5155

5256
impl Entry {
@@ -59,18 +63,20 @@ impl Entry {
5963
Entry::BlockDevice(_) => vec![],
6064
Entry::Fifo(_) => vec![],
6165
Entry::Socket(_) => vec![],
66+
Entry::Unknown(source, _) => source.as_bytes().to_vec(),
6267
}
6368
}
6469

6570
pub fn target(&self) -> &str {
6671
match self {
67-
Entry::Regular(_, target) => target,
68-
Entry::Symlink(_, target) => target,
69-
Entry::Directory(target) => target,
70-
Entry::CharacterDevice(target) => target,
71-
Entry::BlockDevice(target) => target,
72-
Entry::Fifo(target) => target,
73-
Entry::Socket(target) => target,
72+
Entry::Regular(_, target)
73+
| Entry::Symlink(_, target)
74+
| Entry::Directory(target)
75+
| Entry::CharacterDevice(target)
76+
| Entry::BlockDevice(target)
77+
| Entry::Fifo(target)
78+
| Entry::Socket(target)
79+
| Entry::Unknown(_, target) => target,
7480
}
7581
}
7682

@@ -83,6 +89,7 @@ impl Entry {
8389
Entry::BlockDevice(_) => 5,
8490
Entry::Fifo(_) => 6,
8591
Entry::Socket(_) => 7,
92+
Entry::Unknown(..) => 255,
8693
}
8794
}
8895
}
@@ -118,14 +125,13 @@ impl Record for Layout {
118125
5 => FileType::BlockDevice,
119126
6 => FileType::Fifo,
120127
7 => FileType::Socket,
121-
t => return Err(DecodeError::UnknownFileType(t)),
128+
_ => FileType::Unknown,
122129
};
123130

124131
let _padding = reader.read_array::<11>()?;
125132

126133
// Make the layout entry *usable*
127134
let entry = match file_type {
128-
// BUG: boulder stores xxh128 as le bytes not be
129135
FileType::Regular => {
130136
let source = reader.read_vec(source_length as usize)?;
131137
let hash = u128::from_be_bytes(source.try_into().unwrap());
@@ -136,12 +142,16 @@ impl Record for Layout {
136142
sanitize(&reader.read_string(target_length as u64)?).into(),
137143
),
138144
FileType::Directory => Entry::Directory(sanitize(&reader.read_string(target_length as u64)?).into()),
139-
_ => {
140-
if source_length > 0 {
141-
let _ = reader.read_vec(source_length as usize);
142-
}
143-
unreachable!()
145+
FileType::CharacterDevice => {
146+
Entry::CharacterDevice(sanitize(&reader.read_string(target_length as u64)?).into())
144147
}
148+
FileType::BlockDevice => Entry::BlockDevice(sanitize(&reader.read_string(target_length as u64)?).into()),
149+
FileType::Fifo => Entry::Fifo(sanitize(&reader.read_string(target_length as u64)?).into()),
150+
FileType::Socket => Entry::Socket(sanitize(&reader.read_string(target_length as u64)?).into()),
151+
FileType::Unknown => Entry::Unknown(
152+
sanitize(&reader.read_string(source_length as u64)?).into(),
153+
sanitize(&reader.read_string(target_length as u64)?).into(),
154+
),
145155
};
146156

147157
Ok(Self {

crates/stone/src/payload/meta.rs

Lines changed: 39 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ pub struct Meta {
1717
pub kind: Kind,
1818
}
1919

20-
#[repr(u8)]
2120
#[derive(Debug, Clone, Copy, PartialEq, Eq, strum::Display)]
2221
#[strum(serialize_all = "lowercase")]
22+
#[repr(u8)]
2323
pub enum Dependency {
2424
/// Just the plain name of a package
2525
#[strum(serialize = "name")]
@@ -50,9 +50,10 @@ pub enum Dependency {
5050

5151
/// An emul32-compatible pkgconfig .pc dependency (lib32/*.pc)
5252
PkgConfig32,
53+
54+
Unknown = 255,
5355
}
5456

55-
#[repr(u8)]
5657
#[derive(Debug, Clone, PartialEq, Eq)]
5758
pub enum Kind {
5859
Int8(i8),
@@ -66,6 +67,7 @@ pub enum Kind {
6667
String(String),
6768
Dependency(Dependency, String),
6869
Provider(Dependency, String),
70+
Unknown(Vec<u8>),
6971
}
7072

7173
impl Kind {
@@ -85,58 +87,61 @@ impl Kind {
8587
Kind::Dependency(_, s) => s.len() + 2,
8688
// Plus dep size & nul terminator
8789
Kind::Provider(_, s) => s.len() + 2,
90+
Kind::Unknown(data) => data.len(),
8891
}
8992
}
9093
}
9194

92-
#[repr(u16)]
9395
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
96+
#[repr(u16)]
9497
pub enum Tag {
9598
// Name of the package
9699
Name = 1,
97100
// Architecture of the package
98-
Architecture = 2,
101+
Architecture,
99102
// Version of the package
100-
Version = 3,
103+
Version,
101104
// Summary of the package
102-
Summary = 4,
105+
Summary,
103106
// Description of the package
104-
Description = 5,
107+
Description,
105108
// Homepage for the package
106-
Homepage = 6,
109+
Homepage,
107110
// ID for the source package, used for grouping
108-
SourceID = 7,
111+
SourceID,
109112
// Runtime dependencies
110-
Depends = 8,
113+
Depends,
111114
// Provides some capability or name
112-
Provides = 9,
115+
Provides,
113116
// Conflicts with some capability or name
114-
Conflicts = 10,
117+
Conflicts,
115118
// Release number for the package
116-
Release = 11,
119+
Release,
117120
// SPDX license identifier
118-
License = 12,
121+
License,
119122
// Currently recorded build number
120-
BuildRelease = 13,
123+
BuildRelease,
121124
// Repository index specific (relative URI)
122-
PackageURI = 14,
125+
PackageURI,
123126
// Repository index specific (Package hash)
124-
PackageHash = 15,
127+
PackageHash,
125128
// Repository index specific (size on disk)
126-
PackageSize = 16,
129+
PackageSize,
127130
// A Build Dependency
128-
BuildDepends = 17,
131+
BuildDepends,
129132
// Upstream URI for the source
130-
SourceURI = 18,
133+
SourceURI,
131134
// Relative path for the source within the upstream URI
132-
SourcePath = 19,
135+
SourcePath,
133136
// Ref/commit of the upstream source
134-
SourceRef = 20,
137+
SourceRef,
138+
139+
Unknown = u16::MAX,
135140
}
136141

137142
/// Helper to decode a dependency's encoded kind
138-
fn decode_dependency(i: u8) -> Result<Dependency, DecodeError> {
139-
let result = match i {
143+
fn decode_dependency(i: u8) -> Dependency {
144+
match i {
140145
0 => Dependency::PackageName,
141146
1 => Dependency::SharedLibrary,
142147
2 => Dependency::PkgConfig,
@@ -146,9 +151,8 @@ fn decode_dependency(i: u8) -> Result<Dependency, DecodeError> {
146151
6 => Dependency::Binary,
147152
7 => Dependency::SystemBinary,
148153
8 => Dependency::PkgConfig32,
149-
_ => return Err(DecodeError::UnknownDependency(i)),
150-
};
151-
Ok(result)
154+
_ => Dependency::Unknown,
155+
}
152156
}
153157

154158
impl Record for Meta {
@@ -176,7 +180,7 @@ impl Record for Meta {
176180
18 => Tag::SourceURI,
177181
19 => Tag::SourcePath,
178182
20 => Tag::SourceRef,
179-
t => return Err(DecodeError::UnknownMetaTag(t)),
183+
_ => Tag::Unknown,
180184
};
181185

182186
let kind = reader.read_u8()?;
@@ -197,15 +201,15 @@ impl Record for Meta {
197201
9 => Kind::String(sanitize(reader.read_string(length as u64)?)),
198202
10 => Kind::Dependency(
199203
// DependencyKind u8 subtracted from length
200-
decode_dependency(reader.read_u8()?)?,
204+
decode_dependency(reader.read_u8()?),
201205
sanitize(reader.read_string(length as u64 - 1)?),
202206
),
203207
11 => Kind::Provider(
204208
// DependencyKind u8 subtracted from length
205-
decode_dependency(reader.read_u8()?)?,
209+
decode_dependency(reader.read_u8()?),
206210
sanitize(reader.read_string(length as u64 - 1)?),
207211
),
208-
k => return Err(DecodeError::UnknownMetaKind(k)),
212+
_ => Kind::Unknown(reader.read_vec(length as usize)?),
209213
};
210214

211215
Ok(Self { tag, kind })
@@ -224,6 +228,7 @@ impl Record for Meta {
224228
Kind::String(_) => 9,
225229
Kind::Dependency(_, _) => 10,
226230
Kind::Provider(_, _) => 11,
231+
Kind::Unknown(_) => 255,
227232
};
228233

229234
writer.write_u32(self.kind.size() as u32)?;
@@ -250,6 +255,9 @@ impl Record for Meta {
250255
writer.write_all(s.as_bytes())?;
251256
writer.write_u8(b'\0')?;
252257
}
258+
Kind::Unknown(data) => {
259+
writer.write_all(data)?;
260+
}
253261
}
254262

255263
Ok(())

crates/stone/src/payload/mod.rs

Lines changed: 13 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -17,30 +17,32 @@ pub use self::layout::Layout;
1717
pub use self::meta::Meta;
1818
use crate::{ReadExt, WriteExt};
1919

20-
#[repr(u8)]
2120
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
21+
#[repr(u8)]
2222
pub enum Kind {
2323
// The Metadata store
2424
Meta = 1,
2525
// File store, i.e. hash indexed
26-
Content = 2,
26+
Content,
2727
// Map Files to Disk with basic UNIX permissions + types
28-
Layout = 3,
28+
Layout,
2929
// For indexing the deduplicated store
30-
Index = 4,
30+
Index,
3131
// Attribute storage
32-
Attributes = 5,
33-
// For Writer interim
34-
Dumb = 6,
32+
Attributes,
33+
34+
Unknown = 255,
3535
}
3636

37-
#[repr(u8)]
3837
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
38+
#[repr(u8)]
3939
pub enum Compression {
4040
// Payload has no compression
4141
None = 1,
4242
// Payload uses ZSTD compression
43-
Zstd = 2,
43+
Zstd,
44+
45+
Unknown = 255,
4446
}
4547

4648
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
@@ -71,14 +73,13 @@ impl Header {
7173
3 => Kind::Layout,
7274
4 => Kind::Index,
7375
5 => Kind::Attributes,
74-
6 => Kind::Dumb,
75-
k => return Err(DecodeError::UnknownKind(k)),
76+
_ => Kind::Unknown,
7677
};
7778

7879
let compression = match reader.read_u8()? {
7980
1 => Compression::None,
8081
2 => Compression::Zstd,
81-
d => return Err(DecodeError::UnknownCompression(d)),
82+
_ => Compression::Unknown,
8283
};
8384

8485
Ok(Self {
@@ -140,18 +141,6 @@ pub struct Payload<T> {
140141

141142
#[derive(Debug, Error)]
142143
pub enum DecodeError {
143-
#[error("Unknown header type: {0}")]
144-
UnknownKind(u8),
145-
#[error("Unknown header compression: {0}")]
146-
UnknownCompression(u8),
147-
#[error("Unknown metadata type: {0}")]
148-
UnknownMetaKind(u8),
149-
#[error("Unknown metadata tag: {0}")]
150-
UnknownMetaTag(u16),
151-
#[error("Unknown file type: {0}")]
152-
UnknownFileType(u8),
153-
#[error("Unknown dependency type: {0}")]
154-
UnknownDependency(u8),
155144
#[error("io")]
156145
Io(#[from] io::Error),
157146
}

0 commit comments

Comments
 (0)