php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #6361 unpack fails with 'H'
Submitted: 2000-08-25 19:04 UTC Modified: 2000-09-17 17:08 UTC
From: alex at iniciando dot com Assigned:
Status: Closed Package: *General Issues
PHP Version: 4.0.1pl2 OS: RH Linux 6.0
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: alex at iniciando dot com
New email:
PHP Version: OS:

 

 [2000-08-25 19:04 UTC] alex at iniciando dot com
This script fails complaining about there isn't enougth data for unpack:

$md5_val = '0123456789abcdef0123456789abcdef';
print "{$md5_val}<br>\n";
$binary_md5 = pack('H32', $md5_val);

$md5_val = unpack('H32a', $binary_md5);
$md5_val = $md5_val['a'];
print "{$md5_val}<br>\n";

It's corresponding perl scripts works fine:

#!/usr/bin/perl
$md5_val = '0123456789abcdef0123456789abcdef';
print "$md5_val\n";
$binary_md5 = pack('H32', $md5_val);

($md5_val) = unpack('H32', $binary_md5);
print "$md5_val\n";

Workarround:

$md5_val = unpack('H32a', $binary_md5.$binary_md5);

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2000-08-31 09:29 UTC] stas@php.net
Well, PHP unpack seems to behave differently from perl's unpack here. In Perl, number behind H is the number of nibbles, in PHP - number of characters (which is different for the unpack). I don't know if this is an intended behaviour...
 [2000-09-17 17:08 UTC] stas@php.net
Should be fixed in CVS, please check.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Jul 02 14:01:36 2025 UTC