Skip to content
This repository was archived by the owner on Nov 3, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions .github/workflows/fuzz.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ jobs:
run: cargo install cargo-fuzz

- name: Fuzz
run: cargo fuzz run bytes -- -max_total_time=1800 # 30 minutes
# run for 30 minutes with a 2GB memory limit and a maximum input length of 2048 bytes
# the maximum input length is set so that the formatter's size limiter will prevent
# allocating more memory than the memory limit
run: cargo fuzz run bytes -- -max_total_time=1800 -rss_limit_mb=2048 -max_len=2048

string:
name: Fuzz string
Expand All @@ -46,4 +49,7 @@ jobs:
run: cargo install cargo-fuzz

- name: Fuzz
run: cargo fuzz run string -- -max_total_time=1800 # 30 minutes
# run for 30 minutes with a 2GB memory limit and a maximum input length of 2048 bytes
# the maximum input length is set so that the formatter's size limiter will prevent
# allocating more memory than the memory limit
run: cargo fuzz run string -- -max_total_time=1800 -rss_limit_mb=2048 -max_len=2048
2 changes: 2 additions & 0 deletions fuzz/fuzz_targets/bytes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ use mock::MockTime;

fuzz_target!(|data: (MockTime, &[u8])| {
let (time, format) = data;
let _ignored = strftime::bytes::strftime(&time, format);

// Give each fuzzer input a 16kb buffer to write to.
let mut buf = vec![0u8; 16 * 1024].into_boxed_slice();
let _ignored = strftime::buffered::strftime(&time, format, &mut buf[..]);
Expand Down
2 changes: 2 additions & 0 deletions fuzz/fuzz_targets/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ impl<'a> fmt::Write for LimitedBuf<'a> {

fuzz_target!(|data: (MockTime, &str)| {
let (time, format) = data;
let _ignored = strftime::string::strftime(&time, format);

// Give each fuzzer input a 16kb buffer to write to.
let mut buf = vec![0u8; 16 * 1024].into_boxed_slice();

Expand Down
1 change: 1 addition & 0 deletions src/format/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -787,6 +787,7 @@ impl<'t, 'f, T: CheckedTime> TimeFormatter<'t, 'f, T> {

// Use a size limiter to limit the maximum size of the resulting
// formatted string
// Ref: <https://github.com/ruby/ruby/blob/v3_4_2/strftime.c#L921-L928>
let size_limit = self.format.len().saturating_mul(512 * 1024);
let mut f = SizeLimiter::new(buf, size_limit);

Expand Down
5 changes: 5 additions & 0 deletions src/tests/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -795,6 +795,11 @@ fn test_format_invalid() {
let err = get_format_err(&time, format);
assert!(matches!(err, Error::InvalidFormatString));
}

for format in ["\0%", "\0%-4", "\0%-", "\0%-_"] {
let err = get_format_err(&time, format);
assert!(matches!(err, Error::InvalidFormatString));
}
}

#[test]
Expand Down