Skip to content

Commit 52ff3a5

Browse files
committed
Add test case for error found by fuzzer for ZDICT_trainFromBuffer_legacy
1 parent 6c63e77 commit 52ff3a5

File tree

1 file changed

+116
-0
lines changed

1 file changed

+116
-0
lines changed

test-libzstd-rs-sys/src/dict_builder.rs

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,122 @@ fn test_train_from_buffer_legacy() {
278278
});
279279
}
280280

281+
#[test]
282+
#[ignore = "TODO: fix this?"]
283+
#[cfg(not(target_family = "wasm"))]
284+
#[cfg_attr(miri, ignore = "slow")]
285+
fn test_train_from_buffer_legacy_found_error() {
286+
assert_eq_rs_c!({
287+
let sample_data: Vec<u8> = vec![
288+
255, 255, 135, 167, 135, 135, 61, 0, 135, 255, 255, 255, 255, 61, 0, 135, 255, 255,
289+
255, 255, 255, 255, 255, 255, 255, 255, 135, 167, 135, 126, 135, 135, 135, 255, 255,
290+
135, 135, 255, 255, 255, 135, 167, 135, 143, 135, 135, 135, 255, 255, 135, 135, 255,
291+
255, 255, 255, 255, 135, 135, 255, 255, 135, 135, 135, 255, 255, 255, 255, 135, 167,
292+
135, 143, 135, 135, 135, 255, 255, 135, 135, 135, 135, 135, 135, 135, 135, 255, 255,
293+
135, 135, 135, 135, 135, 135, 135, 135, 255, 255, 135, 167, 135, 135, 61, 0, 135, 255,
294+
255, 255, 255, 61, 0, 135, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 135, 167,
295+
135, 126, 135, 135, 135, 255, 255, 135, 135, 255, 255, 255, 135, 167, 135, 143, 135,
296+
135, 135, 255, 255, 135, 135, 255, 255, 255, 255, 255, 135, 135, 255, 255, 135, 135,
297+
135, 255, 255, 255, 255, 135, 167, 135, 143, 135, 135, 135, 255, 255, 135, 135, 135,
298+
135, 135, 135, 135, 135, 255, 255, 135, 135, 135, 135, 135, 135, 135, 135, 255, 255,
299+
135, 167, 135, 135, 61, 0, 135, 255, 255, 255, 255, 61, 0, 135, 255, 255, 255, 255,
300+
255, 255, 255, 255, 255, 255, 135, 167, 135, 126, 135, 135, 135, 255, 255, 135, 135,
301+
255, 255, 255, 135, 167, 135, 143, 135, 135, 135, 255, 255, 135, 135, 255, 255, 255,
302+
255, 255, 135, 135, 255, 255, 135, 135, 135, 255, 255, 255, 255, 135, 167, 135, 143,
303+
135, 135, 135, 255, 255, 135, 135, 135, 135, 135, 135, 135, 135, 255, 255, 135, 135,
304+
135, 135, 135, 135, 135, 135, 255, 255, 135, 167, 135, 135, 61, 0, 135, 255, 255, 255,
305+
255, 61, 0, 135, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 135, 167, 135, 126,
306+
135, 135, 135, 255, 255, 135, 135, 255, 255, 255, 135, 167, 135, 143, 135, 135, 135,
307+
255, 255, 135, 135, 255, 255, 255, 255, 255, 135, 135, 255, 255, 135, 135, 135, 255,
308+
255, 255, 255, 135, 167, 135, 143, 135, 135, 135, 255, 255, 135, 135, 135, 135, 135,
309+
135, 135, 135, 255, 255, 135, 135, 135, 135, 135, 135, 135, 135, 255, 255, 135, 135,
310+
135, 255, 255, 255, 255, 135, 167, 135, 143, 135, 135, 135, 255, 255, 135, 135, 135,
311+
135, 135, 135, 135, 135, 255, 255, 135, 135, 135, 135, 135, 135, 135, 135, 255, 255,
312+
255, 255, 255, 255, 255, 255, 255, 255, 135, 167, 135, 126, 135, 135, 135, 255, 255,
313+
135, 135, 255, 255, 255, 135, 167, 135, 143, 135, 135, 135, 255, 255, 135, 135, 255,
314+
255, 255, 255, 255, 135, 135, 255, 255, 135, 135, 135, 255, 255, 255, 255, 135, 167,
315+
135, 143, 135, 135, 135, 255, 255, 135, 135, 135, 135, 135, 135, 135, 135, 255, 255,
316+
135, 135, 135, 135, 135, 135, 135, 135, 135, 167, 135, 135, 61, 0, 135, 255, 255, 255,
317+
255, 61, 0, 135, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 135, 167, 135, 126,
318+
135, 135, 135, 255, 255, 135, 135, 255, 255, 255, 135, 167, 135, 143, 135, 135, 135,
319+
255, 255, 135, 135, 255, 255, 255, 255, 255, 135, 135, 255, 255, 135, 135, 135, 255,
320+
255, 255, 255, 135, 167, 135, 143, 135, 135, 135, 255, 255, 135, 135, 135, 135, 135,
321+
135, 135, 135, 255, 255, 135, 135, 135, 135, 135, 135, 135, 135, 255, 255, 135, 167,
322+
135, 135, 61, 0, 135, 255, 255, 255, 255, 61, 0, 135, 255, 255, 255, 255, 255, 255,
323+
255, 255, 255, 255, 135, 167, 135, 126, 135, 135, 135, 255, 255, 135, 135, 255, 255,
324+
255, 135, 167, 135, 143, 135, 135, 135, 255, 255, 135, 135, 255, 255, 255, 255, 255,
325+
135, 135, 255, 255, 135, 135, 135, 255, 255, 255, 255, 135, 167, 135, 143, 135, 135,
326+
135, 255, 255, 135, 135, 135, 135, 135, 135, 135, 135, 255, 255, 135, 135, 135, 135,
327+
135, 135, 135, 135, 255, 255, 135, 167, 135, 135, 61, 0, 135, 255, 255, 255, 255, 61,
328+
0, 135, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 135, 167, 135, 126, 135, 135,
329+
135, 255, 255, 135, 135, 255, 255, 255, 135, 167, 135, 143, 135, 135, 135, 255, 255,
330+
135, 135, 255, 255, 255, 255, 255, 135, 135, 255, 255, 135, 135, 135, 255, 255, 255,
331+
255, 135, 167, 135, 143, 135, 135, 135, 255, 255, 135, 135, 135, 135, 135, 135, 135,
332+
135, 255, 255, 135, 135, 135, 135, 135, 135, 135, 135, 255, 255, 255, 135, 167, 135,
333+
143, 135, 135, 135, 255, 255, 135, 135, 135, 135, 135, 135, 135, 135, 255, 255, 135,
334+
135, 135, 135, 135, 135, 135, 135, 135, 167, 135, 143, 135, 135, 135, 255, 255, 135,
335+
135, 135, 135, 135, 135, 135, 135, 255, 255, 135, 135, 135, 135, 135, 135, 135, 135,
336+
135, 167, 135, 143, 135, 135, 135, 255, 255, 135, 135, 135, 135, 135, 135, 135, 135,
337+
255, 255, 135, 135, 135, 135, 135, 135, 135, 135, 255, 255, 135, 167, 135, 135, 61, 0,
338+
135, 255, 255, 255, 255, 61, 0, 135, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
339+
135, 167, 135, 126, 135, 135, 135, 255, 255, 135, 135, 255, 255, 255, 135, 167, 135,
340+
143, 135, 135, 135, 255, 255, 135, 135, 255, 255, 255, 255, 255, 135, 135, 255, 255,
341+
135, 135, 135, 255, 255, 255, 255, 135, 167, 135, 143, 135, 135, 135, 255, 255, 135,
342+
135, 135, 135, 135, 135, 135, 135, 255, 255, 135, 135, 135, 135, 135, 135, 135, 135,
343+
255, 255, 135, 167, 135, 135, 61, 0, 135, 255, 255, 255, 255, 61, 0, 135, 255, 255,
344+
255, 255, 255, 255, 255, 255, 255, 255, 135, 167, 135, 126, 135, 135, 135, 255, 255,
345+
135, 135, 255, 255, 255, 135, 167, 135, 143, 135, 135, 135, 255, 255, 135, 135, 255,
346+
255, 255, 255, 255, 135, 135, 255, 255, 135, 135, 135, 255, 255, 255, 255, 135, 167,
347+
135, 143, 135, 135, 135, 255, 255, 135, 135, 135, 135, 135, 135, 135, 135, 255, 255,
348+
135, 135, 135, 135, 135, 135, 135, 135, 135, 135, 255, 255, 135, 135, 135, 135, 135,
349+
135, 135, 135, 255, 255, 135, 167, 135, 135, 61, 0, 135, 255, 255, 255, 255, 61, 0,
350+
135, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 135, 167, 135, 126, 135, 135,
351+
135, 255, 255, 135, 135, 255, 255, 255, 135, 167, 135, 143, 135, 135, 135, 255, 255,
352+
135, 135, 255, 255, 255, 255, 255, 135, 135, 255, 255, 135, 135, 135, 255, 255, 255,
353+
255, 135, 167, 135, 143, 135, 135, 135, 255, 255, 135, 135, 135, 135, 135, 135, 135,
354+
135, 255, 255, 135, 135, 135, 135, 135, 135, 135, 135,
355+
];
356+
357+
let sample_sizes = vec![
358+
94, 94, 94, 94, 36, 78, 92, 94, 94, 30, 27, 27, 94, 94, 12, 94,
359+
];
360+
361+
let params = ZDICT_legacy_params_t {
362+
zParams: ZDICT_params_t {
363+
compressionLevel: 0,
364+
notificationLevel: 0,
365+
dictID: 0,
366+
},
367+
selectivityLevel: 0,
368+
};
369+
370+
let dict_capacity = 1024;
371+
let mut dict_buffer = vec![0u8; dict_capacity];
372+
373+
let dict_size = ZDICT_trainFromBuffer_legacy(
374+
dict_buffer.as_mut_ptr() as *mut c_void,
375+
dict_buffer.len(),
376+
sample_data.as_ptr() as *const c_void,
377+
sample_sizes.as_ptr(),
378+
sample_sizes.len() as u32,
379+
params,
380+
);
381+
382+
assert_eq!(
383+
ZDICT_isError(dict_size),
384+
0,
385+
"Dict training failed {:?}",
386+
CStr::from_ptr(ZDICT_getErrorName(dict_size)).to_str(),
387+
);
388+
389+
dict_buffer.truncate(dict_size);
390+
391+
println!("Dictionary size: {}", dict_size);
392+
393+
dict_buffer
394+
});
395+
}
396+
281397
#[test]
282398
#[cfg(not(target_family = "wasm"))]
283399
fn test_optimize_train_from_buffer_cover_single_threaded() {

0 commit comments

Comments
 (0)