From 341d20883d125a718415c46375b22c6a5e795223 Mon Sep 17 00:00:00 2001 From: Zoe Roux Date: Sun, 17 Apr 2022 13:17:35 +0200 Subject: [PATCH] Fixing tracks array size with unknown/font tracks --- src/Kyoo.Core/Controllers/Transcoder.cs | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/Kyoo.Core/Controllers/Transcoder.cs b/src/Kyoo.Core/Controllers/Transcoder.cs index bff0ddd1..b684271d 100644 --- a/src/Kyoo.Core/Controllers/Transcoder.cs +++ b/src/Kyoo.Core/Controllers/Transcoder.cs @@ -142,16 +142,15 @@ namespace Kyoo.Core.Controllers tracks = new Track[trackCount]; int j = 0; - for (int i = 0; i < arrayLength; i++) + for (int i = 0; i < arrayLength; i++, streamsPtr += size) { FTrack stream = Marshal.PtrToStructure(streamsPtr); - if (stream!.Type != FTrackType.Unknown && stream.Type != FTrackType.Attachment) - { - tracks[j] = stream.ToTrack(); - j++; - } - streamsPtr += size; + if (stream!.Type == FTrackType.Unknown || stream.Type == FTrackType.Attachment) + continue; + tracks[j] = stream.ToTrack(); + j++; } + Array.Resize(ref tracks, j); } else tracks = Array.Empty(); @@ -207,11 +206,12 @@ namespace Kyoo.Core.Controllers { if (fastStop && _initialized) return; - if (TranscoderAPI.Init() == Marshal.SizeOf()) - return; + if (TranscoderAPI.Init() != Marshal.SizeOf()) + { + _logger.LogCritical("The transcoder library could not be initialized correctly"); + throw new HealthException("The transcoder library is corrupted or invalid."); + } _initialized = true; - _logger.LogCritical("The transcoder library could not be initialized correctly"); - throw new HealthException("The transcoder library is corrupted or invalid."); } ///