Skip to content

date:fix date +%9223372036854775807c panic#11046

Open
mattsu2020 wants to merge 7 commits intouutils:mainfrom
mattsu2020:date_11044
Open

date:fix date +%9223372036854775807c panic#11046
mattsu2020 wants to merge 7 commits intouutils:mainfrom
mattsu2020:date_11044

Conversation

@mattsu2020
Copy link
Contributor

@mattsu2020 mattsu2020 commented Feb 21, 2026

Summary

Fixes a crash in date when parsing extremely large GNU width modifiers (fixes #11044).

What Changed

Made apply_modifiers fallible (Result<String, FormatError>), so allocation-related failures can be propagated safely.
Replaced infallible large padding construction with checked/fallible logic:
Added an explicit error path with message: field width too large.
Propagated this through existing invalid-format handling so date returns a normal error instead of aborting.

Update `apply_modifiers` to return `Result<String, FormatError>` and check for integer overflow when calculating padding length. This prevents potential panics or incorrect formatting when very large width values are specified. The change adds proper error handling for the "field width too large" case and propagates errors through the formatting pipeline.
…ormance

Replace `std::iter::repeat().take()` patterns with `std::iter::repeat_n()` in format_modifiers.rs. This change improves performance by avoiding the overhead of the `take()` iterator adapter and directly creating an iterator that yields the exact number of elements needed.
@github-actions
Copy link

GNU testsuite comparison:

Congrats! The gnu test tests/tail/tail-n0f is now passing!

@sylvestre
Copy link
Contributor

it would be nice to verify the code before submitting it for review...

const ERR_FIELD_WIDTH_TOO_LARGE: &str = "field width too large";

fn width_too_large_error() -> FormatError {
FormatError::Custom(ERR_FIELD_WIDTH_TOO_LARGE.to_string())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why this function ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For this PR, we will make modifications individually rather than standardizing them.
If necessary, we will refactor the wording for standardization in a separate PR.

/// Custom error message (reserved for future use)
#[allow(dead_code)]
/// Custom error message
Custom(String),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please rename custom for something more useful

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've made it easier to understand.

}
}

const ERR_FIELD_WIDTH_TOO_LARGE: &str = "field width too large";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please don't use the const and use translate!() instead

  • the message is too generic

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fix

.arg(&format)
.fails()
.code_is(1)
.stderr_contains("field width too large");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but it passes with gnu, no ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In GNU 9.10, the same command returned exit 1. To avoid wording discrepancies, the test focuses on checking for a failure code.

Added proper error handling for format modifier width calculations that could overflow or fail allocation. The change replaces generic error messages with a specific error type `FieldWidthTooLarge` that includes the problematic width and specifier values, improving error reporting for date format operations.
- Changed FormatError::FieldWidthTooLarge to store width as String instead of usize
- Updated error message generation to use FluentArgs for proper localization
- Fixed width parsing to return FormatError instead of panicking on parse failure
- Updated error message formatting to use get_message_with_args for consistency
- Fixed test assertions to compare width as String instead of usize
@github-actions
Copy link

GNU testsuite comparison:

Skipping an intermittent issue tests/pr/bounded-memory (passes in this run but fails in the 'main' branch)
Congrats! The gnu test tests/date/date-locale-hour is no longer failing!

@sylvestre
Copy link
Contributor

sorry, it needs to be rebased

# Conflicts:
#	src/uu/date/src/format_modifiers.rs
#	tests/by-util/test_date.rs
@github-actions
Copy link

github-actions bot commented Mar 4, 2026

GNU testsuite comparison:

GNU test failed: tests/tail/retry. tests/tail/retry is passing on 'main'. Maybe you have to rebase?
Skip an intermittent issue tests/pr/bounded-memory (fails in this run but passes in the 'main' branch)
Note: The gnu test tests/tail/tail-n0f is now being skipped but was previously passing.
Congrats! The gnu test tests/seq/seq-epipe is now passing!

@github-actions
Copy link

github-actions bot commented Mar 5, 2026

GNU testsuite comparison:

Skipping an intermittent issue tests/pr/bounded-memory (passes in this run but fails in the 'main' branch)
Note: The gnu test tests/printf/printf-surprise is now being skipped but was previously passing.
Congrats! The gnu test tests/cut/bounded-memory is now passing!
Congrats! The gnu test tests/dd/no-allocate is now passing!

Reorganized imports in format_modifiers.rs to group related modules together for better code organization. Also improved error message formatting in test_date.rs by adding proper assertion formatting for macOS date setting error messages.
@github-actions
Copy link

github-actions bot commented Mar 5, 2026

GNU testsuite comparison:

Skipping an intermittent issue tests/pr/bounded-memory (passes in this run but fails in the 'main' branch)
Note: The gnu test tests/cut/cut-huge-range is now being skipped but was previously passing.
Note: The gnu test tests/expand/bounded-memory is now being skipped but was previously passing.
Congrats! The gnu test tests/dd/no-allocate is now passing!
Skip an intermittent issue tests/cut/bounded-memory (was skipped on 'main', now failing)

@codspeed-hq
Copy link

codspeed-hq bot commented Mar 5, 2026

Merging this PR will improve performance by 3.33%

⚡ 1 improved benchmark
✅ 303 untouched benchmarks
⏩ 42 skipped benchmarks1

Performance Changes

Mode Benchmark BASE HEAD Efficiency
Simulation du_summarize_balanced_tree[(5, 4, 10)] 6.8 ms 6.6 ms +3.33%

Comparing mattsu2020:date_11044 (e2a344b) with main (1f7c81f)

Open in CodSpeed

Footnotes

  1. 42 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

date: date +%9223372036854775807c panic

2 participants