php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #33333 strpos (and other functions) not seeing a character that is very clearly there
Submitted: 2005-06-14 07:50 UTC Modified: 2005-06-15 07:38 UTC
From: FxChiP at Gmail dot com Assigned:
Status: Not a bug Package: Strings related
PHP Version: 4.3.11 OS: *nix most likely
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: FxChiP at Gmail dot com
New email:
PHP Version: OS:

 

 [2005-06-14 07:50 UTC] FxChiP at Gmail dot com
Description:
------------
Using explode(), strpos(), and probably any other string-related function in conjunction with a string returned from fgets() will (at least sometimes) produce an incorrect result. 

i.e. if there is a line like this in a file called public_covers.db:

FxChiP?this is a test statement?guitar?akczf.pk.gif?whee?1113865622?1113967262

The *entire string* will be the first element in the array created by explode(). More information is included in the reproduce code. 

Contents of the public_covers.db file:

FxChiP?this is a test statement?guitar?akczf.pk.gif?whee?1113865622?1113967262
duality515?Vermilion Pt2?bass?jimroot54_vermilionpt2.mp3?pwnage?1113877848?1113967262
duality515?Everything Ends?guitar?macca_everythingends.mp3?w00t?1113967262?1113967262
duality515?gsg?bass?temp.jpg??1116469075?1113967262



Reproduce code:
---------------
<?PHP
	$public_db = fopen("public_covers.db", "r");
	$bwerp = explode('?', fgets($public_db));
	var_dump($bwerp);
?>

Expected result:
----------------
From the var_dump, I'd expect to see an array consisting of everything "in between" the ? characters.

Actual result:
--------------
array(1) { [0]=>  string(84) "FxChiP?this is a test statement?guitar?akczf.pk.gif?whee?1113865622?1113967262 " }

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-06-14 08:45 UTC] rasmus@php.net
Nice bug #

For reports like this, you really need to provide the od -c or od -x output of both the relevant bits of the script file and the input file.  I think you will find that what is in the file and what is in the script are two different things that whatever you are using to view both just happen to look similar.  Just because two things look similar does not mean that it is the same byte sequence behind them.
 [2005-06-15 07:28 UTC] FxChiP at Gmail dot com
...

My error. As it turns out, using GNOME's gedit (aka "Text Editor" under Accessories) on the offending PHP scripts is what actually caused the problem.

It caused a  character to be prepended before the § which is what probably caused the error. I fixed this by opening the test-script in an editor that doesn't put strange characters in. ;) (eVim/gVim to be exact, but emacs should work too, I'm not trying to start a flamewar if that's even possible on a bug tracker)

My apologies for not trying everything and filing a bug before it was absolutely necessary, which took up valuable hard drive space on your servers. I'll try to be more careful next time :)
 [2005-06-15 07:38 UTC] rasmus@php.net
Not a bug then
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Thu Dec 05 18:01:24 2019 UTC