Skip to content

Fix panic on truncated strftime padding modifier#782

Open
SAY-5 wants to merge 1 commit into
time-rs:mainfrom
SAY-5:fix-strftime-padding-oob
Open

Fix panic on truncated strftime padding modifier#782
SAY-5 wants to merge 1 commit into
time-rs:mainfrom
SAY-5:fix-strftime-padding-oob

Conversation

@SAY-5
Copy link
Copy Markdown

@SAY-5 SAY-5 commented Jun 6, 2026

Closes #781.

When a strftime format string ends right after a padding modifier (%_, %-, %0), the tokenizer reads self.input[2] for the component byte without checking that it exists, so parse_strftime_borrowed("%_") panics with an index-out-of-bounds instead of returning an error. This splits the padding match out and uses get(2) so a missing component yields the same Expected error the parser already returns elsewhere.

…modifier

Signed-off-by: Sai Asish Y <say.apm35@gmail.com>
@codecov
Copy link
Copy Markdown

codecov Bot commented Jun 6, 2026

Codecov Report

❌ Patch coverage is 91.66667% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 88.3%. Comparing base (eb08b40) to head (7217e92).

Files with missing lines Patch % Lines
time/src/format_description/parse/strftime.rs 91.7% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##            main    #782     +/-   ##
=======================================
+ Coverage   88.2%   88.3%   +0.1%     
=======================================
  Files         99      99             
  Lines      13030   13037      +7     
=======================================
+ Hits       11494   11510     +16     
+ Misses      1536    1527      -9     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

parse_strftime_borrowed panics on truncated padding modifier ("%_", "%-", "%0")

1 participant