diff --git a/Neos.Cache/Classes/Backend/SimpleFileBackend.php b/Neos.Cache/Classes/Backend/SimpleFileBackend.php index 47604ef17a..292c8274f9 100644 --- a/Neos.Cache/Classes/Backend/SimpleFileBackend.php +++ b/Neos.Cache/Classes/Backend/SimpleFileBackend.php @@ -503,7 +503,16 @@ protected function readCacheFile(string $cacheEntryPathAndFilename, int $offset if ($offset !== null) { fseek($file, $offset); } - $data = fread($file, $maxlen !== null ? $maxlen : filesize($cacheEntryPathAndFilename) - (int)$offset); + + $length = $maxlen !== null ? $maxlen : filesize($cacheEntryPathAndFilename) - (int)$offset; + + // fread requires a positive length. If the file is empty, we just return an empty string. + if ($length === 0) { + $data = ''; + } else { + $data = fread($file, $length); + } + flock($file, LOCK_UN); } fclose($file); diff --git a/Neos.Cache/Tests/Unit/Backend/SimpleFileBackendTest.php b/Neos.Cache/Tests/Unit/Backend/SimpleFileBackendTest.php index e42231f533..127f5121aa 100644 --- a/Neos.Cache/Tests/Unit/Backend/SimpleFileBackendTest.php +++ b/Neos.Cache/Tests/Unit/Backend/SimpleFileBackendTest.php @@ -222,6 +222,22 @@ public function getReturnsContentOfTheCorrectCacheFile() self::assertSame($data2, $simpleFileBackend->get($entryIdentifier)); } + /** + * @test + */ + public function getSupportsEmptyData() + { + $this->mockCacheFrontend->expects(self::any())->method('getIdentifier')->will(self::returnValue('UnitTestCache')); + + $data = ''; + $entryIdentifier = 'SimpleFileBackendTest'; + + $simpleFileBackend = $this->getSimpleFileBackend(); + $simpleFileBackend->set($entryIdentifier, $data); + + self::assertSame($data, $simpleFileBackend->get($entryIdentifier)); + } + /** * @test */