find: -printf: don't panic on a multibyte char after an octal escape#723
Merged
Merged
Conversation
`\NNN` octal escapes were parsed by slicing a fixed 3 bytes off the format string, which panics when fewer than 3 octal digits are followed by a multibyte character (e.g. `-printf '\0€'`): the 3-byte slice lands inside the multibyte char and trips a char-boundary assertion. Parse the octal escape from the leading octal digits only (1 to 3, all ASCII) and advance by their byte length. This also fixes `\1`..`\7`, which previously fell through to the single-character escape table and errored instead of being treated as octal, matching GNU find.
Contributor
|
thanks for also proposing PR ! |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #723 +/- ##
=======================================
Coverage 91.83% 91.84%
=======================================
Files 35 35
Lines 7129 7149 +20
Branches 375 375
=======================================
+ Hits 6547 6566 +19
- Misses 437 438 +1
Partials 145 145 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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 #720
find -printf '\NNN'octal escapes were parsed by slicing a fixed 3 bytes off the format string. When fewer than 3 octal digits are followed by a multibyte character (e.g.-printf '\0€'), that 3-byte slice lands inside the multibyte char and panics on a UTF-8 char-boundary assertion (exit 101); GNUfindexits 0.The octal escape is now parsed from its leading octal digits only (1 to 3, all ASCII) and the parser advances by their byte length, so a following multibyte char is never sliced into.
This also fixes
\1..\7: previously only\0was recognised and\1..\7fell through to the single-character escape table and errored, instead of being treated as octal — now matching GNUfind.Verified byte-for-byte against GNU for
\0€,\1😀,\00é,\101,\012X. Added a regression unit test.