瀏覽代碼

Fix content-length check to look at the last header received, fixes #5268

Jordi Boggiano 9 年之前
父節點
當前提交
c66639fe03
共有 1 個文件被更改,包括 4 次插入5 次删除
  1. 4 5
      src/Composer/Util/RemoteFilesystem.php

+ 4 - 5
src/Composer/Util/RemoteFilesystem.php

@@ -277,7 +277,8 @@ class RemoteFilesystem
         try {
         try {
             $result = file_get_contents($fileUrl, false, $ctx);
             $result = file_get_contents($fileUrl, false, $ctx);
 
 
-            if ($this->bytesMax && Platform::strlen($result) < $this->bytesMax) {
+            $contentLength = !empty($http_response_header[0]) ? $this->findHeaderValue($http_response_header, 'content-length') : null;
+            if ($contentLength && Platform::strlen($result) < $contentLength) {
                 // alas, this is not possible via the stream callback because STREAM_NOTIFY_COMPLETED is documented, but not implemented anywhere in PHP
                 // alas, this is not possible via the stream callback because STREAM_NOTIFY_COMPLETED is documented, but not implemented anywhere in PHP
                 throw new TransportException('Content-Length mismatch');
                 throw new TransportException('Content-Length mismatch');
             }
             }
@@ -525,14 +526,12 @@ class RemoteFilesystem
                 break;
                 break;
 
 
             case STREAM_NOTIFY_FILE_SIZE_IS:
             case STREAM_NOTIFY_FILE_SIZE_IS:
-                if ($this->bytesMax < $bytesMax) {
-                    $this->bytesMax = $bytesMax;
-                }
+                $this->bytesMax = $bytesMax;
                 break;
                 break;
 
 
             case STREAM_NOTIFY_PROGRESS:
             case STREAM_NOTIFY_PROGRESS:
                 if ($this->bytesMax > 0 && $this->progress) {
                 if ($this->bytesMax > 0 && $this->progress) {
-                    $progression = round($bytesTransferred / $this->bytesMax * 100);
+                    $progression = min(100, round($bytesTransferred / $this->bytesMax * 100));
 
 
                     if ((0 === $progression % 5) && 100 !== $progression && $progression !== $this->lastProgress) {
                     if ((0 === $progression % 5) && 100 !== $progression && $progression !== $this->lastProgress) {
                         $this->lastProgress = $progression;
                         $this->lastProgress = $progression;