Skip to content

Commit e4535df

Browse files
more wip changes
1 parent afbe552 commit e4535df

File tree

1 file changed

+37
-29
lines changed

1 file changed

+37
-29
lines changed

src/types_fuzzer.rs

Lines changed: 37 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ unsafe impl GlobalAlloc for LimitedAllocator {
5252
const MAX_ALLOC: usize = 10 * 1024 * 1024; // 10 MB
5353

5454
if layout.size() > MAX_ALLOC {
55+
println!("ASDF ALLOCATION OF {} BYTES EXCEEDS LIMIT OF {} BYTES", layout.size(), MAX_ALLOC);
5556
panic!(
5657
"Allocation of {} bytes exceeds limit of {} bytes",
5758
layout.size(),
@@ -105,15 +106,19 @@ fn process_type<T: Serialize + serde::de::DeserializeOwned>(
105106
// Create bincode configuration with size limits
106107
let config = bincode::config::DefaultOptions::new()
107108
.with_limit(10_000_000) // Limit to 10MB (adjust as needed)
108-
.with_fixint_encoding();
109-
110-
let typ: T = if let Ok(h) = config.deserialize(&bincode_slice[1..]) {
111-
h
112-
} else {
113-
return Some(TypeEffects {
114-
result: 1,
115-
..Default::default()
116-
});
109+
.with_fixint_encoding()
110+
.allow_trailing_bytes();
111+
112+
let res = config.deserialize::<T>(&bincode_slice[1..]);
113+
let typ = match res {
114+
Ok(h) => { h }
115+
Err(err) => {
116+
println!("ASDF TYPE SERIALIZE FAILED: {}", err);
117+
return Some(TypeEffects {
118+
result: 1,
119+
..Default::default()
120+
});
121+
}
117122
};
118123

119124
let mut ser = MemoryRepresentationSerializer::new();
@@ -146,6 +151,9 @@ pub fn execute_type(input: TypeContext) -> Option<TypeEffects> {
146151
let bincode_slice: &[u8] =
147152
unsafe { std::slice::from_raw_parts(input.content.as_ptr(), input.content.len()) };
148153

154+
println!("ASDF TYPE ID: {} {:?}", bincode_slice[0], bincode_slice.len());
155+
/* FIXME: This type lookup table is AWFUL and needs to be
156+
replaced with something that doesn't have hardcoded indices. */
149157
match bincode_slice[0] {
150158
0 => process_type::<Hash>(bincode_slice),
151159
2 => process_type::<Signature>(bincode_slice),
@@ -159,26 +167,26 @@ pub fn execute_type(input: TypeContext) -> Option<TypeEffects> {
159167
16 => process_type::<EpochSchedule>(bincode_slice),
160168
17 => process_type::<RentCollector>(bincode_slice),
161169
18 => process_type::<StakeHistoryEntry>(bincode_slice),
162-
19 => process_type::<StakeHistory>(bincode_slice),
163-
22 => process_type::<VoteAccounts>(bincode_slice),
164-
33 => process_type::<BankIncrementalSnapshotPersistence>(bincode_slice),
165-
34 => process_type::<NodeVoteAccounts>(bincode_slice),
166-
37 => process_type::<EpochStakes>(bincode_slice),
167-
42 => process_type::<BankHashStats>(bincode_slice),
168-
50 => process_type::<VersionedEpochStakes>(bincode_slice),
169-
56 => process_type::<PohConfig>(bincode_slice),
170-
60 => process_type::<Clock>(bincode_slice),
171-
61 => process_type::<LastRestartSlot>(bincode_slice),
172-
94 => process_type::<EpochRewards>(bincode_slice),
173-
155 => process_type::<ConfigKeys>(bincode_slice),
174-
171 => process_type::<FrozenHashStatus>(bincode_slice),
175-
172 => process_type::<FrozenHashVersioned>(bincode_slice),
176-
213 => process_type::<CrdsData>(bincode_slice),
177-
215 => process_type::<CrdsFilter>(bincode_slice),
178-
216 => process_type::<CrdsValue>(bincode_slice),
179-
225 => process_type::<RepairRequestHeader>(bincode_slice),
180-
230 => process_type::<RepairProtocol>(bincode_slice),
181-
245 => process_type::<DuplicateSlotProof>(bincode_slice),
170+
20 => process_type::<StakeHistory>(bincode_slice),
171+
21 => process_type::<VoteAccounts>(bincode_slice),
172+
34 => process_type::<BankIncrementalSnapshotPersistence>(bincode_slice),
173+
35 => process_type::<NodeVoteAccounts>(bincode_slice),
174+
38 => process_type::<EpochStakes>(bincode_slice),
175+
43 => process_type::<BankHashStats>(bincode_slice),
176+
51 => process_type::<VersionedEpochStakes>(bincode_slice),
177+
57 => process_type::<PohConfig>(bincode_slice),
178+
61 => process_type::<Clock>(bincode_slice),
179+
62 => process_type::<LastRestartSlot>(bincode_slice),
180+
95 => process_type::<EpochRewards>(bincode_slice),
181+
156 => process_type::<ConfigKeys>(bincode_slice),
182+
172 => process_type::<FrozenHashStatus>(bincode_slice),
183+
173 => process_type::<FrozenHashVersioned>(bincode_slice),
184+
214 => process_type::<CrdsData>(bincode_slice),
185+
216 => process_type::<CrdsFilter>(bincode_slice),
186+
217 => process_type::<CrdsValue>(bincode_slice),
187+
226 => process_type::<RepairRequestHeader>(bincode_slice),
188+
231 => process_type::<RepairProtocol>(bincode_slice),
189+
246 => process_type::<DuplicateSlotProof>(bincode_slice),
182190
_ => {
183191
eprintln!("Invalid type ID: {}", bincode_slice[0]);
184192
None

0 commit comments

Comments
 (0)