From cfbf52ef11c936fbd2437b8e35b47cbba6b3fb4b Mon Sep 17 00:00:00 2001 From: niksedk Date: Wed, 5 Aug 2026 06:09:55 +0200 Subject: [PATCH] Guard the missing mdia box in the MP4 track picker PickMp4TrackViewModel.Initialize dereferenced track.Mdia unconditionally for four members and then guarded it with ?. for the fifth. The compiler carried that maybe-null state back over the loop edge, so the first unguarded access warned: PickMp4TrackViewModel.cs(66,31): warning CS8602: Dereference of a possibly null reference. Mp4Parser.GetSubtitleTracks() drops mdia-less traks, so no shipping call path can hit it today - but Initialize takes any List, and the mixed style left it ambiguous which way the code meant to lean. The track's mdia is now read once into a local and skipped when absent, which settles the question and drops the UI project to zero warnings. Co-Authored-By: Claude Opus 5 --- .../PickMp4Track/PickMp4TrackViewModel.cs | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/ui/Features/Shared/PickMp4Track/PickMp4TrackViewModel.cs b/src/ui/Features/Shared/PickMp4Track/PickMp4TrackViewModel.cs index 8c2436ff04..f083651741 100644 --- a/src/ui/Features/Shared/PickMp4Track/PickMp4TrackViewModel.cs +++ b/src/ui/Features/Shared/PickMp4Track/PickMp4TrackViewModel.cs @@ -61,13 +61,22 @@ public void Initialize(List mp4Tracks, string fileName) WindowTitle = $"Pick MP4 track - {fileName}"; foreach (var track in _mp4Tracks) { + // A trak box without an mdia child carries no media information at all; + // Mp4Parser.GetSubtitleTracks() already drops those, but the callers are + // free to hand us any track list. + var mdia = track.Mdia; + if (mdia == null) + { + continue; + } + var display = new Mp4TrackInfoDisplay { - HandlerType = track.Mdia.HandlerType, - Name = track.Mdia.Name, - StartPosition = track.Mdia.StartPosition, - IsVobSubSubtitle = track.Mdia.IsVobSubSubtitle, - Duration = LastCueEnd(track.Mdia?.Minf?.Stbl?.GetParagraphs()), + HandlerType = mdia.HandlerType, + Name = mdia.Name, + StartPosition = mdia.StartPosition, + IsVobSubSubtitle = mdia.IsVobSubSubtitle, + Duration = LastCueEnd(mdia.Minf?.Stbl?.GetParagraphs()), Track = track, }; Tracks.Add(display);