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: 2020-10-11 18:20 UTC
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: magrodriguez93 at gmail dot com Assigned: cataphract (profile)
Status: Closed Package: rar (PECL)
PHP Version: Irrelevant OS: Debian 4.16.16-2
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 this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: magrodriguez93 at gmail dot com
New email:
PHP Version: OS:

 

 [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.
 [2020-10-11 18:20 UTC] cataphract@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: cataphract
 [2020-10-11 18:20 UTC] cataphract@php.net
Fixed in 4.1.0, although with a different patch.
 [2020-10-11 18:20 UTC] cataphract@php.net
Fixed in 4.1.0, although with a different patch.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 08:01:28 2024 UTC