From 2e08f195e45966387f5b5d5e76ef8a8d7cf7a8e3 Mon Sep 17 00:00:00 2001 From: Taloth Saldono Date: Sun, 19 Mar 2017 22:02:52 +0100 Subject: [PATCH] Fixed: Zero length file causes MediaInfo hanging in 100% cpu load. --- src/NzbDrone.Core/MediaFiles/MediaInfo/MediaInfoLib.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/NzbDrone.Core/MediaFiles/MediaInfo/MediaInfoLib.cs b/src/NzbDrone.Core/MediaFiles/MediaInfo/MediaInfoLib.cs index b7b2f7d38..b18e2e462 100644 --- a/src/NzbDrone.Core/MediaFiles/MediaInfo/MediaInfoLib.cs +++ b/src/NzbDrone.Core/MediaFiles/MediaInfo/MediaInfoLib.cs @@ -189,6 +189,11 @@ public int Open(string fileName) public int Open(Stream stream) { + if (stream.Length < 1024) + { + return 0; + } + var isValid = (int)MediaInfo_Open_Buffer_Init(_handle, stream.Length, 0); if (isValid == 1) { @@ -203,7 +208,7 @@ public int Open(Stream stream) totalRead += bufferRead; var status = (BufferStatus)MediaInfo_Open_Buffer_Continue(_handle, buffer, (IntPtr)bufferRead); - + if (status.HasFlag(BufferStatus.Finalized) || status <= 0 || bufferRead == 0) { Logger.Trace("Read file offset {0}-{1} ({2} bytes)", seekStart, stream.Position, stream.Position - seekStart);