From 27ef5dfd936261be203c5b96f1452bee1c6bc8c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Molakvo=C3=A6?= <14975046+skjnldsv@users.noreply.github.com> Date: Tue, 1 Dec 2026 18:52:42 +0100 Subject: [PATCH] fix(preview): close the streams on an invalid 64-bit atom size MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit getSparseFile() closed the video stream and the sparse file on every early return but this one, so both stayed open on a malformed MP4/MOV. Fixes #67354 Assisted-by: ClaudeCode:claude-opus-5-5 Signed-off-by: John Molakvoæ <14975046+skjnldsv@users.noreply.github.com> --- lib/private/Preview/Movie.php | 2 ++ tests/lib/Preview/MovieSparseFileTest.php | 34 +++++++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 tests/lib/Preview/MovieSparseFileTest.php diff --git a/lib/private/Preview/Movie.php b/lib/private/Preview/Movie.php index f695080f099b4..23181f1f570f3 100644 --- a/lib/private/Preview/Movie.php +++ b/lib/private/Preview/Movie.php @@ -233,6 +233,8 @@ private function getSparseFile(File $file, int $size): string|false { $atomSize = (int)hexdec(bin2hex(stream_get_contents($content, 8, (int)($offset + 8)))); // 0 in the 64 bit field should not occur in a valid file, stop processing if ($atomSize === 0) { + fclose($content); + fclose($sparseFile); return false; } } diff --git a/tests/lib/Preview/MovieSparseFileTest.php b/tests/lib/Preview/MovieSparseFileTest.php new file mode 100644 index 0000000000000..0b215a1987843 --- /dev/null +++ b/tests/lib/Preview/MovieSparseFileTest.php @@ -0,0 +1,34 @@ +createMock(File::class); + $file->method('getSize')->willReturn(strlen($content)); + $file->method('fopen')->willReturn($stream); + + $result = self::invokePrivate(new Movie(), 'getSparseFile', [$file, 10]); + + $this->assertFalse($result); + $this->assertFalse(is_resource($stream)); + } +}