php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #76592 Incorrect buffer_size calculation with streams
Submitted: 2018-07-06 23:58 UTC Modified: 2018-07-07 00:06 UTC
From: magrodriguez93 at gmail dot com Assigned:
Status: Open Package: rar (PECL)
PHP Version: Irrelevant OS: Debian 4.16.16-2
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2018-07-06 23:58 UTC] magrodriguez93 at gmail dot com
Description:
------------
Whenever the unpacked size of a file is greater than RAR_CHUNK_BUFFER_SIZE only RAR_CHUNK_BUFFER_SIZE bytes are allocated for the stream, resulting in incomplete reads.

Generate a random 10MB file and add it to a RAR archive.

dd if=/dev/urandom of=test.dat bs=1M count=10 && rar a test.rar test.dat

Test script:
---------------
$rar = \RarArchive::open('test.rar');
if ($rar === false)
    die('Unable to open archive.');

$entry = $rar->getEntry('test.dat');
if ($entry === false)
    die('Unable to get entry.');

$contents = stream_get_contents($entry->getStream(), $entry->getUnpackedSize());
$expectedCRC = $entry->getCrc();
$actualCRC = dechex(crc32($contents));

if ($expectedCRC !== $actualCRC)
    die('CRC values do not match.');

die('All ok.');






Expected result:
----------------
The CRC values should match.

Actual result:
--------------
The CRC values do not match whenever the unpacked size is greater than RAR_CHUNK_BUFFER_SIZE.

Patches

Fix-incorrect-buffer_size-calculation-with-streams (last revision 2018-07-06 23:58 UTC by magrodriguez93 at gmail dot com)

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2018-07-07 00:06 UTC] magrodriguez93 at gmail dot com
I believe this will also fix https://bugs.php.net/bug.php?id=66796 as the number of read bytes matches what I was getting and the expected number was greater than RAR_CHUNK_BUFFER_SIZE.
 
PHP Copyright © 2001-2018 The PHP Group
All rights reserved.
Last updated: Sat Dec 15 11:01:25 2018 UTC