Fix(previews): prevent infinite loop in case of bad video file

Signed-off-by: invario <67800603+invario@users.noreply.github.com>
This commit is contained in:
invario 2025-09-05 09:32:37 -04:00
parent acb26a4507
commit ba51caf5f4
No known key found for this signature in database
GPG key ID: 0DEB3BD5A327B965

View file

@ -164,6 +164,10 @@ class Movie extends ProviderV2 {
// size of the atom. Needed for large atoms like 'mdat' (the video data)
if ($atomSize === 1) {
$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) {
return false;
}
}
}
// Found the 'moov' atom, store its location and size
@ -194,9 +198,9 @@ class Movie extends ProviderV2 {
// Copy first $size bytes of video into new file
stream_copy_to_stream($content, $sparseFile, $size, 0);
// If 'moov' is located before $size in the video, it was already streamed,
// If 'moov' is located entirely before $size in the video, it was already streamed,
// so no need to download it again.
if ($moovOffset >= $size) {
if ($moovOffset + $moovSize >= $size) {
// Seek to where 'moov' atom needs to be placed
fseek($content, (int)$moovOffset);
fseek($sparseFile, (int)$moovOffset);