Skip to content

Commit 75d2a9e

Browse files
Merge branch '5.1' into 5.2
* 5.1: µCS fix CS fix CS fix [travis] use PHP 8.0 to patch return types and run deps=low Add me as a Notifier code owner Update sl_SI translations Don't trigger deprecation for deprecated aliases pointing to deprecated definitions [HttpFoundation] use atomic writes in MockFileSessionStorage Make EmailMessage & SmsMessage transport nullable remove unused argument [DI] fix param annotation [Config] Add \Symfony\Component\Config\Loader::load() return type Simplify PHP CS Fixer config Rename normalize param
2 parents c92fcef + 0edfc5d commit 75d2a9e

File tree

3 files changed

+19
-7
lines changed

3 files changed

+19
-7
lines changed

BinaryFileResponse.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -301,8 +301,8 @@ public function sendContent()
301301
return $this;
302302
}
303303

304-
$out = fopen('php://output', 'wb');
305-
$file = fopen($this->file->getPathname(), 'rb');
304+
$out = fopen('php://output', 'w');
305+
$file = fopen($this->file->getPathname(), 'r');
306306

307307
stream_copy_to_stream($file, $out, $this->maxlen, $this->offset);
308308

Request.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1546,7 +1546,7 @@ public function getContent(bool $asResource = false)
15461546

15471547
$this->content = false;
15481548

1549-
return fopen('php://input', 'rb');
1549+
return fopen('php://input', 'r');
15501550
}
15511551

15521552
if ($currentContentIsResource) {

Session/Storage/MockFileSessionStorage.php

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,10 @@ public function save()
102102

103103
try {
104104
if ($data) {
105-
file_put_contents($this->getFilePath(), serialize($data));
105+
$path = $this->getFilePath();
106+
$tmp = $path.bin2hex(random_bytes(6));
107+
file_put_contents($tmp, serialize($data));
108+
rename($tmp, $path);
106109
} else {
107110
$this->destroy();
108111
}
@@ -122,8 +125,11 @@ public function save()
122125
*/
123126
private function destroy(): void
124127
{
125-
if (is_file($this->getFilePath())) {
128+
set_error_handler(static function () {});
129+
try {
126130
unlink($this->getFilePath());
131+
} finally {
132+
restore_error_handler();
127133
}
128134
}
129135

@@ -140,8 +146,14 @@ private function getFilePath(): string
140146
*/
141147
private function read(): void
142148
{
143-
$filePath = $this->getFilePath();
144-
$this->data = is_readable($filePath) && is_file($filePath) ? unserialize(file_get_contents($filePath)) : [];
149+
set_error_handler(static function () {});
150+
try {
151+
$data = file_get_contents($this->getFilePath());
152+
} finally {
153+
restore_error_handler();
154+
}
155+
156+
$this->data = $data ? unserialize($data) : [];
145157

146158
$this->loadSession();
147159
}

0 commit comments

Comments
 (0)