MCPcopy Create free account
hub / github.com/erans/pgsqlite / generate_fuzz_inputs

Function generate_fuzz_inputs

tests/protocol_fuzzing_test.rs:210–247  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

208// Fuzz input generators
209
210fn generate_fuzz_inputs() -> Vec<Vec<u8>> {
211 let mut inputs = Vec::new();
212
213 // Empty input
214 inputs.push(vec![]);
215
216 // Single byte inputs
217 for b in 0..=255u8 {
218 inputs.push(vec![b]);
219 }
220
221 // Common message type prefixes with random data
222 let message_types = [b'Q', b'P', b'B', b'E', b'S', b'X', b'H', b'D', b'C', b'F'];
223 for &msg_type in &message_types {
224 for len in [0, 1, 4, 8, 16, 64, 256, 1024] {
225 let mut msg = vec![msg_type];
226 msg.extend_from_slice(&(len as u32).to_be_bytes());
227 msg.extend(vec![0; len.min(1024)]); // Limit to prevent memory issues
228 inputs.push(msg);
229 }
230 }
231
232 // Random byte sequences
233 for len in [1, 4, 16, 64, 256, 1024] {
234 let mut rng_data = vec![0u8; len];
235 for i in 0..len {
236 rng_data[i] = (i * 37 + 113) as u8; // Deterministic "random"
237 }
238 inputs.push(rng_data);
239 }
240
241 // Malformed length headers
242 inputs.push(vec![b'Q', 0xFF, 0xFF, 0xFF, 0xFF]); // Max u32 length
243 inputs.push(vec![b'Q', 0x00, 0x00, 0x00, 0x00]); // Zero length
244 inputs.push(vec![b'Q', 0x00, 0x00, 0x00]); // Incomplete length
245
246 inputs
247}
248
249fn generate_startup_message_fuzzing() -> Vec<Vec<u8>> {
250 let mut inputs = Vec::new();

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected