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
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
37 - 4 = ?
Subscribe to this entry?

 
 [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: Fri Apr 19 06:01:29 2024 UTC