Skip to content

Commit bfb5db8

Browse files
authored
Merge pull request #54918 from invario/fix-preview-sparse-file
2 parents f2ee9ec + ba51caf commit bfb5db8

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

lib/private/Preview/Movie.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,10 @@ private function getSparseFile(File $file, int $size): string|false {
164164
// size of the atom. Needed for large atoms like 'mdat' (the video data)
165165
if ($atomSize === 1) {
166166
$atomSize = (int)hexdec(bin2hex(stream_get_contents($content, 8, (int)($offset + 8))));
167+
// 0 in the 64 bit field should not occur in a valid file, stop processing
168+
if ($atomSize === 0) {
169+
return false;
170+
}
167171
}
168172
}
169173
// Found the 'moov' atom, store its location and size
@@ -194,9 +198,9 @@ private function getSparseFile(File $file, int $size): string|false {
194198
// Copy first $size bytes of video into new file
195199
stream_copy_to_stream($content, $sparseFile, $size, 0);
196200

197-
// If 'moov' is located before $size in the video, it was already streamed,
201+
// If 'moov' is located entirely before $size in the video, it was already streamed,
198202
// so no need to download it again.
199-
if ($moovOffset >= $size) {
203+
if ($moovOffset + $moovSize >= $size) {
200204
// Seek to where 'moov' atom needs to be placed
201205
fseek($content, (int)$moovOffset);
202206
fseek($sparseFile, (int)$moovOffset);

0 commit comments

Comments
 (0)