8000 bug #28278 [HttpFoundation] Fix unprepared BinaryFileResponse sends e… · symfony/symfony@b547855 · GitHub
[go: up one dir, main page]

Skip to content

Commit b547855

Browse files
committed
bug #28278 [HttpFoundation] Fix unprepared BinaryFileResponse sends empty file (wackymole)
This PR was merged into the 2.8 branch. Discussion ---------- [HttpFoundation] Fix unprepared BinaryFileResponse sends empty file | Q | A | ------------- | --- | Branch? | 2.8 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes, with the exception of preexisting, unrelated failures | Fixed tickets | #28237 | License | MIT | Doc PR | When you call `BinaryFileResponse#sendContent()` without first calling `prepare()` the response is sent but the contents are empty. `prepare()` properly initializes the `$maxlen` and `$offset` properties. However, `sendContent()` doesn't do any sanity checking, and so, uses the uninitialized properties. This causes `stream_copy_to_stream()` to copy empty contents and the file that is sent, to contain nothing. This change initializes the properties at definition instead of in `prepare()`. > Additionally: > - Bug fixes must be submitted against the lowest branch where they apply ~I'm not sure how early this bug exists, or how far back to go. I'll check to see if 2.7 and 2.8 are affected and report back.~ Commits ------- dba8687 Instantiate $offset and $maxlen at definition
2 parents 2554ad0 + dba8687 commit b547855

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

src/Symfony/Component/HttpFoundation/BinaryFileResponse.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ class BinaryFileResponse extends Response
3131
* @var File
3232
*/
3333
protected $file;
34-
protected $offset;
35-
protected $maxlen;
34+
protected $offset = 0;
35+
protected $maxlen = -1;
3636
protected $deleteFileAfterSend = false;
3737

3838
/**

src/Symfony/Component/HttpFoundation/Tests/BinaryFileResponseTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,19 @@ public function provideFullFileRanges()
206206
);
207207
}
208208

209+
public function testUnpreparedResponseSendsFullFile()
210+
{
211+
$response = BinaryFileResponse::create(__DIR__.'/File/Fixtures/test.gif', 200);
212+
213+
$data = file_get_contents(__DIR__.'/File/Fixtures/test.gif');
214+
215+
$this->expectOutputString($data);
216+
$response = clone $response;
217+
$response->sendContent();
218+
219+
$this->assertEquals(200, $response->getStatusCode());
220+
}
221+
209222
/**
210223
* @dataProvider provideInvalidRanges
211224
*/

0 commit comments

Comments
 (0)
0