find: -printf: advance past a full char in advance_one to avoid a multibyte panic#731
Open
leeewee wants to merge 1 commit into
Open
find: -printf: advance past a full char in advance_one to avoid a multibyte panic#731leeewee wants to merge 1 commit into
leeewee wants to merge 1 commit into
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #731 +/- ##
=======================================
Coverage 91.86% 91.87%
=======================================
Files 35 35
Lines 7153 7160 +7
Branches 375 375
=======================================
+ Hits 6571 6578 +7
Misses 437 437
Partials 145 145 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
advance_one read a full `char` via front() but then dropped it by slicing one byte (`&self.string[1..]`). When that char is multibyte (e.g. a `€` after a `%` conversion, a `\` escape, or a `%A`/`%C`/`%T` time directive), byte index 1 is not a char boundary and the slice panics. Advance by the char's UTF-8 length so multibyte input routes through the normal handling instead of aborting.
94d6c7a to
13da7cc
Compare
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.
Fixes #730
advance_oneread a fullcharviafront()but then dropped it by slicing one byte (&self.string[1..]). When that char is multibyte (e.g.€after a%conversion, a\escape, or a%A/%C/%Ttime directive), byte index 1 is not a char boundary, so the slice panicked:(also
\€and%A€/%C€/%T€)This advances by the leading char's UTF-8 length (
c.len_utf8()) instead of a fixed1, so a multibyte char routes through the normal handling instead of aborting — the same multibyte-aware approach #723 applied topeek. Unrecognized escapes / invalid time specifiers keep their existing behavior (a multibyte char now behaves exactly like its ASCII equivalent, e.g.\€like\q).Added a regression test (
test_parse_multibyte_char_after_directive).