-
Notifications
You must be signed in to change notification settings - Fork 7.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix GH-15824 mb_detect_encoding() invalid "UTF8" #15829
Conversation
@@ -332,6 +332,10 @@ const mbfl_encoding *mbfl_name2encoding_ex(const char *name, size_t name_len) | |||
} | |||
#endif | |||
|
|||
if (name_len == 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This check shouldn't be necessary
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. Removed.
ext/mbstring/tests/gh15824.phpt
Outdated
mbstring | ||
--FILE-- | ||
<?php | ||
echo mb_detect_encoding('abc', 'UTF8, ASCII'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add more test cases such that both mime names and aliases are tested.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added.
@@ -349,7 +353,7 @@ const mbfl_encoding *mbfl_name2encoding_ex(const char *name, size_t name_len) | |||
/* search MIME charset name */ | |||
for (encoding = mbfl_encoding_ptr_list; *encoding; encoding++) { | |||
if ((*encoding)->mime_name) { | |||
if (strcasecmp((*encoding)->mime_name, name) == 0) { | |||
if (strcasecmp((*encoding)->mime_name, name) == 0 && strlen((*encoding)->mime_name) == name_len) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should use strncasecmp and the same == '\0'
check that I suggested below.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you very much for pretty code. Fixed.
21970ab
to
98678e6
Compare
@@ -349,7 +349,7 @@ const mbfl_encoding *mbfl_name2encoding_ex(const char *name, size_t name_len) | |||
/* search MIME charset name */ | |||
for (encoding = mbfl_encoding_ptr_list; *encoding; encoding++) { | |||
if ((*encoding)->mime_name) { | |||
if (strcasecmp((*encoding)->mime_name, name) == 0) { | |||
if (strcasecmp((*encoding)->mime_name, name) == 0 && (*encoding)->mime_name[name_len] == '\0') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You still need strncasecmp
here too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice catch, thanks.
d3c83d1
to
439a76e
Compare
I fixed from strcasecmp to strncasecmp. However, strncasecmp is specify size to php#3 parameter. Hence, Add check length to mime and aliases. Co-authored-by: Niels Dossche <[email protected]>
439a76e
to
d005317
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
@youkidearitai Indeed, thanks. It seems you are a committer for |
@alexdowad Thank you for confirmed. Add my account for CODEOWNERS file is already applied in #14744 . Thank you. |
@youkidearitai Thanks very much 👍 In future, it will be appreciated if you can CC me on such changes. As a suggestion, if you want to list yourself as a 2nd mbstring maintainer in EXTENSIONS, I have no objection to that. |
Okay. I will do in next time.
Thank you. I will add myself for EXTENSIONS. |
I fixed from strcasecmp to strncasecmp.
However, strncasecmp is specify size to 3rd parameter.
Hence, Add check strlen to mime and aliases.