ZF-10299: S3 Stream wrapper incorrectly reads data due to incorrect Range headers

Issue Type: Bug Created: 2010-08-12T02:59:49.000+0000 Last Updated: 2011-02-17T06:55:28.000+0000 Status: Resolved Fix version(s): - 1.11.4 (03/Mar/11)

Reporter: Dave Marshall (musher) Assignee: Alexander Veremyev (alexander) Tags: - Zend_Service_Amazon

Related issues: Attachments:


The range headers should read

0-8191 for the first 8192 bytes, instead we send 0-8192

To test:

<pre class="highlight">

define('AWS_KEY', 'a key');
define('AWS_SECRET_KEY', 'a secret');

require_once 'Zend/Service/Amazon/S3.php';

$s3 = new Zend_Service_Amazon_S3(AWS_KEY, AWS_SECRET_KEY);


copy('./test.pdf', '<a>s3://bucket-name/test.pdf</a>');
copy('<a>s3://bucket-name/test.pdf</a>', 'test2.pdf');

var_dump(file_get_contents('test.pdf') == file_get_contents('test2.pdf'));

Simple patch

<pre class="literal">
Index: Zend/Service/Amazon/S3/Stream.php
--- Zend/Service/Amazon/S3/Stream.php   (revision 22829)
+++ Zend/Service/Amazon/S3/Stream.php   (working copy)
@@ -194,7 +194,7 @@
         $range_start = $this->_position;
-        $range_end = $this->_position+$count;
+        $range_end = $this->_position+$count-1;
         // Only fetch more data from S3 if we haven't fetched any data yet (postion=0)
         // OR, the range end position is greater than the size of the current object


Posted by Giraldo Rosales (nitrog7) on 2010-10-07T14:38:31.000+0000

This solved my problem. If you stream out a jpeg image that is large enough (950px x 750px) the bottom half will be distorted. Adding this fix solved the problem.

Posted by Mark Mitchenall (mitchenall) on 2011-01-12T16:37:36.000+0000

Thank you. Patch fixed the issue for me too.

Posted by Dave Marshall (musher) on 2011-01-14T07:15:04.000+0000

Given that this bug leads to data loss, perhaps someone with commit privileges can get it resolved?

Posted by Alexander Veremyev (alexander) on 2011-02-17T06:55:27.000+0000

Checked fix to be complaint to HTTP RFC, added minor correction to the fix.


Have you found an issue?

See the Overview section for more details.


© 2006-2016 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.