|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #57395 getCRC() weird results
Submitted: 2006-11-26 03:31 UTC Modified: 2009-11-19 00:25 UTC
From: php_rar at elberethzone dot net Assigned:
Status: Closed Package: rar (PECL)
PHP Version: 5.2.1 OS: Windows Server 2003
Private report: No CVE-ID: None
 [2006-11-26 03:31 UTC] php_rar at elberethzone dot net
The problem is, the value returned by getCRC() is wrong for some entries: Not the true CRC as returned by WinRAR 3.61 or a CRC-32 calculation directly done on the file.

As a sidenote, the documentation of this extension indicates getCRC() returns an integer, which is not the case. It returns a string containing the hex representation of the integer.

The reproduce code is opening the first RAR of a 26 files set (20 971 520 bytes each).

Here is a link to execute the code (if needed):

I am using Apache 2.2.3 with PHP 5.2.0 and the latest compiled php_rar.dll from PECL (I guess it is 0.3.1 Beta).

Reproduce code:
$rarfile = rar_open('DW-PCFX-0001-ZENKI-K3K.part01.rar');
$listentries = rar_list($rarfile);
for ($y=0;$y<count($listentries);$y++) {
  echo str_pad(basename($listentries[$y]->getName()),32, " ", STR_PAD_RIGHT);
  echo str_pad($listentries[$y]->getUnpackedSize(),16," ",STR_PAD_LEFT).'   ';
  echo str_pad($listentries[$y]->getCrc(),8," ",STR_PAD_LEFT);
  echo "\n";

Expected result:
DW-PCFX-0001-ZENKI-K3K.bin             773257632   3d7e8c9c
DW-PCFX-0001-ZENKI-K3K.cue                   909   af8919ff
DW-PCFX-0001-ZENKI-K3K.toc.txt               789   6df9c294

Actual result:
DW-PCFX-0001-ZENKI-K3K.bin             773257632     151529
DW-PCFX-0001-ZENKI-K3K.cue                   909   af8919ff
DW-PCFX-0001-ZENKI-K3K.toc.txt               789   6df9c294


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2006-11-26 06:30 UTC] php_rar at elberethzone dot net
Just tested with unrar v3.60 and RAR v3.61 and both of them gives same results as php_rar extension. So this is not a bug and actually just the way it works. From what I guess on a multi-part RAR the entry spawned on various part get its CRC updated as archive goes on. Well... I will adapt my code to take this into account.

The final complete file CRC can be found on the last RAR part containing a chunk of the file.
 [2006-11-26 06:35 UTC] php_rar at elberethzone dot net
Well I comment again because there is no way to obtain the correct CRC by using this extension. If I use last RAR from the set (.part26.rar) the first entry just do not show up.

I really think this extension should list the right CRC with getCRC() and not just the one stored in the first RAR. With the unrar command line program this can be solved by using the unrar -v switch (list all volumes). Dunno how to fix that...
 [2006-11-26 07:03 UTC] php_rar at elberethzone dot net
Here is what I think must be done (I am really not skilled enough in C++ & Win32 compiling of PHP Extensions to do more):

The HEAD_FLAGS field of the File Block must have:
If bit flags 0x01 is set in the HEAD_FLAGS field of a File Block then the bit flags 0x02 must not be set (that means this is the last volume). Then the FILE_CRC field has the right value! If you have 0x01 set & 0x02 the processing must go to next volume to process further. Maybe that can be an option of rar_list?
 [2007-02-13 18:30 UTC] tony2001 at phpclub dot net
Where can I get the archive file which demonstrates the issue?
 [2007-02-14 01:33 UTC] php_rar at elberethzone dot net
The link has changed:

The small RAR set can be obtained there:

Please note I updated my server to Apache 2.2.4 & PHP 5.2.1 with PECL Extensions 5.2.1.

Since my bug report I have created a CGI program that handles the RAR files correctly (in Delphi) using the behaviour I explain in my previous comment.
 [2007-02-14 07:32 UTC]
I get the same result with unrar utility, so it's unrar problem.

 unrar v dw-v3-test2.part1.rar

UNRAR 3.41 freeware      Copyright (c) 1993-2004 Alexander Roshal

Volume dw-v3-test2.part1.rar

                  Size   Packed Ratio  Date   Time     Attr      CRC   Meth Ver
                   100       87  87% 19-01-01 13:35  .....A.   CB72AD91 m5g 2.9
               2097152   511787  --> 03-01-05 13:19  .....A.   684683A0 m5g 2.9
    2          2097252   511874  24%       volume 1
 [2007-02-14 07:41 UTC] php_rar at elberethzone dot net
Indeed same "wrong" results with Unrar & correct behaviour with RAR.

But at least with unrar if you open each RAR file in the set you can get all "good" values. But with php_unrar you cannot.
 [2009-11-19 00:25 UTC] glopes at nebm dot ist dot utl dot pt
Fixed in revision #290964.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 18 18:01:28 2024 UTC