[php-src] Issue #13844: hex2bin() returning a base64 encoded string
| From: | elnath78 | Date: | Sat, 30 Mar 2024 19:23:10 +0000 |
| Subject: | [php-src] Issue #13844: hex2bin() returning a base64 encoded string | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-246683@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/13844
Author: elnath78
### Description
This is one of those situations that puzzles me to a point where I give up. I have a PHP page with a
very simple task, here is what it does:
```
//r contains hexadecimal representation of an ordinary ASCII string, not base 64 encoded
if (isset($_GET['r'])){
$r = $_GET['r'];
$r = hex2bin($r);
//at this point $r contain a base64 encoded string
//and precisely the same string it was initially parsed into hexadecimal
//so it is not only converting to binary/ascii but also encoding for some reason
}
```
So way before any sanitization or anything I just cannot convert the string back to binary, what
puzzles me (if receiving a base64 encoded string was not enough) is that if I run the same thing on
a
test.php page, it works correctly:
```
<!doctype html>
<html lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
</head>
<body>
<?php
$r = $_GET['r'];
$r = hex2bin($r);
echo $r;
?>
</body>
</html>
```
But oddities are not over, if I try to decode the base64 string in my script, I obtain back the same
base64 string, there must be something really weird going on in my PC and specifically this page,
for some reason. I'm running XAMPP with PHP 8.2 and I never received a base64 encoded string
from a hex2bin() function.
The original string was ÉGOÏSTE some letters are not being converted back correctly
using online tools (same script above) however they are replaced with the usual � converting it to
�GO�STE so probably the sample text might have something to do with the problem,
however why is it working in a test page running in the same environment? Why ever the function is
returning a base64 encoded string?
I could not find a rference or case, when hex2bin will return a base64 encoded string.
### PHP Version
8.2.0
### Operating System
Windows 10 with XAMPP x64