date: cap format width to i32::MAX to prevent OOM#11377
Draft
sylvestre wants to merge 1 commit intouutils:mainfrom
Draft
date: cap format width to i32::MAX to prevent OOM#11377sylvestre wants to merge 1 commit intouutils:mainfrom
sylvestre wants to merge 1 commit intouutils:mainfrom
Conversation
|
GNU testsuite comparison: |
|
GNU testsuite comparison: |
collinfunk
reviewed
Mar 18, 2026
src/uu/date/src/format_modifiers.rs
Outdated
| // GNU date appears to cap output at around 1000 characters, | ||
| // so we'll use a similar limit. | ||
| const MAX_WIDTH: usize = 1000; | ||
| let width: usize = width_str.parse::<usize>().unwrap_or(0).min(MAX_WIDTH); |
There was a problem hiding this comment.
I'm a bit confused by this claim:
$ date -d 2024-01-01 "+r++%++8888888888r+%" | wc -c
8888888894
$ ./target/debug/date -d 2024-01-01 "+r++%++8888888888r+%" | wc -c
1006
Contributor
There was a problem hiding this comment.
GNU date limit is about i64::MAX - 3, and it errors instead of capping output:
$ date --version
date (GNU coreutils) 9.10
$ date -d 2024-01-01 "+r++%++9223372036854775805r+%"
r++gdate: fprintftime error: Result too large
Contributor
Author
There was a problem hiding this comment.
please don't share links to GNU's projects. The licenses are not compatible.
Contributor
|
Should we just error instead of capping width? |
Contributor
|
There is still the issue that our implementation allocates too much memory for width of Since there is no reasonable use case anyway, we could cap or error at |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
found by the fuzzer