ZF-10299: S3 Stream wrapper incorrectly reads data due to incorrect Range headers
Description
The range headers should read
0-8191 for the first 8192 bytes, instead we send 0-8192
To test:
<?php
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);
$s3->registerStreamWrapper("s3");
copy('./test.pdf', 's3://bucket-name/test.pdf');
copy('s3://bucket-name/test.pdf', 'test2.pdf');
var_dump(file_get_contents('test.pdf') == file_get_contents('test2.pdf'));
Simple patch
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
Comments
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.
Fixed.