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
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: delda at virgilio dot it
New email:
PHP Version: OS:

 

 [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-2022 The PHP Group
All rights reserved.
Last updated: Mon Sep 26 13:05:56 2022 UTC