php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #67386 wrong assignment in mbfl_identify_encoding2
Submitted: 2014-06-05 13:43 UTC Modified: 2017-07-22 20:07 UTC
From: delda at virgilio dot it Assigned:
Status: Not a bug Package: mbstring related
PHP Version: Irrelevant OS: All
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
1 + 1 = ?
Subscribe to this entry?

 
 [2014-06-05 13:43 UTC] delda at virgilio dot it
Description:
------------
I think that in the function 'mbfl_identify_encoding2' (in ext/mbstring/libmbfl/mbfl/mbfilter.c), the variable 'bad' was instantiated in a wrong place.

The same is in 'mbfl_encoding_detector_feed' and 'mbfl_identify_encoding'

Test script:
---------------
	if (p != NULL) {
		bad = 0;
		while (n > 0) {
			for (i = 0; i < num; i++) {
				[...]
			}
			if ((num - 1) <= bad && !strict) {
				break;
			}
			p++;
			n--;
		}
	}

I think that 'bad' variable must be inner the while cycle, otherwise the if control on bad number detect is very poor.


Patches

bad_variable_mbfilter2 (last revision 2014-07-07 14:50 UTC by delda at virgilio dot it)
bad_variable_mbfilter (last revision 2014-06-05 13:45 UTC by delda at virgilio dot it)

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2014-07-05 23:08 UTC] yohgaki@php.net
Could you send patch rather than whole file? or pull request?
 [2017-07-22 20:07 UTC] nikic@php.net
-Status: Open +Status: Not a bug
 [2017-07-22 20:07 UTC] nikic@php.net
The assignment is in the right place for what the code wants to do: If there are N possible encodings and N-1 of them have reported an error, then the code considers the last surviving one to be the correct one.

Whether that makes sense is another question, see bug #72933.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Apr 23 09:01:27 2024 UTC