[vlc-commits] [Git][videolan/vlc][master] 3 commits: macosx: Check for validity of internal _vlcInputItem on every property access of VLCInputItem

Felix Paul Kühne (@fkuehne) gitlab at videolan.org
Sun Mar 16 12:37:57 UTC 2025



Felix Paul Kühne pushed to branch master at VideoLAN / VLC


Commits:
cdae1d0b by Claudio Cambra at 2025-03-16T12:15:45+00:00
macosx: Check for validity of internal _vlcInputItem on every property access of VLCInputItem

Prevent crashes from accessing null pointer

Signed-off-by: Claudio Cambra <developer at claudiocambra.com>

- - - - -
ed237a76 by Claudio Cambra at 2025-03-16T12:15:45+00:00
macosx: Make input item options property nullable

Signed-off-by: Claudio Cambra <developer at claudiocambra.com>

- - - - -
dd316430 by Claudio Cambra at 2025-03-16T12:15:45+00:00
macosx: Make input item children nullable

If the internal vlc input item t is null

Signed-off-by: Claudio Cambra <developer at claudiocambra.com>

- - - - -


6 changed files:

- modules/gui/macosx/library/VLCInputItem.h
- modules/gui/macosx/library/VLCInputItem.m
- modules/gui/macosx/library/VLCLibrarySegment.m
- modules/gui/macosx/library/media-source/VLCMediaSourceBaseDataSource.m
- modules/gui/macosx/library/media-source/VLCMediaSourceDataSource.m
- modules/gui/macosx/playqueue/VLCPlaybackContinuityController.m


Changes:

=====================================
modules/gui/macosx/library/VLCInputItem.h
=====================================
@@ -75,7 +75,7 @@ extern NSString * const VLCInputItemCommonDataDifferingFlagString;
 @property (readwrite) NSURL *artworkURL;
 @property (readonly) BOOL preparsed;
 @property (readonly) BOOL isStream;
- at property (readonly) NSArray<NSString *> *options;
+ at property (readonly, nullable) NSArray<NSString *> *options;
 
 - (void)parseInputItem;
 - (void)cancelParsing;
@@ -96,7 +96,7 @@ NSDictionary<NSString *, id> * const commonInputItemData(NSArray<VLCInputItem*>
 @property (readonly) struct input_item_node_t *vlcInputItemNode;
 @property (readonly, nullable) VLCInputItem *inputItem;
 @property (readonly) int numberOfChildren;
- at property (readonly) NSArray <VLCInputNode *> *children;
+ at property (readonly, nullable) NSArray <VLCInputNode *> *children;
 
 @end
 


=====================================
modules/gui/macosx/library/VLCInputItem.m
=====================================
@@ -635,8 +635,12 @@ static const struct input_item_parser_cbs_t parserCallbacks =
     [NSWorkspace.sharedWorkspace activateFileViewerSelectingURLs:@[pathUrl]];
 }
 
-- (NSArray<NSString *> *)options
+- (nullable NSArray<NSString *> *)options
 {
+    if (_vlcInputItem == NULL) {
+        return nil;
+    }
+
     const int i_options = _vlcInputItem->i_options;
     NSMutableArray * const options = [NSMutableArray arrayWithCapacity:i_options];
     for (NSUInteger i = 0; i < i_options; ++i) {
@@ -748,7 +752,7 @@ NSString * const value_##prop =
 - (NSString *)description
 {
     NSString *inputItemName;
-    if (_vlcInputItemNode->p_item)
+    if (_vlcInputItemNode && _vlcInputItemNode->p_item)
         inputItemName = toNSStr(_vlcInputItemNode->p_item->psz_name);
     else
         inputItemName = @"p_item == nil";
@@ -757,11 +761,14 @@ NSString * const value_##prop =
 
 - (int)numberOfChildren
 {
-    return _vlcInputItemNode->i_children;
+    return _vlcInputItemNode ? _vlcInputItemNode->i_children : 0;
 }
 
-- (NSArray<VLCInputNode *> *)children
+- (nullable NSArray<VLCInputNode *> *)children
 {
+    if (_vlcInputItemNode == NULL) {
+        return nil;
+    }
     NSMutableArray *mutableArray = [[NSMutableArray alloc] initWithCapacity:_vlcInputItemNode->i_children];
     for (int i = 0; i < _vlcInputItemNode->i_children; i++) {
         VLCInputNode *inputNode = [[VLCInputNode alloc] initWithInputNode:_vlcInputItemNode->pp_children[i]];


=====================================
modules/gui/macosx/library/VLCLibrarySegment.m
=====================================
@@ -71,8 +71,10 @@ NSArray<NSString *> *defaultBookmarkedLocations()
         VLCInputNode * const rootNode = mediaSource.rootNode;
         [mediaSource preparseInputNodeWithinTree:rootNode];
 
-        for (VLCInputNode * const node in rootNode.children) {
-            [locationMrls addObject:node.inputItem.MRL];
+        if (rootNode.children != nil) {
+            for (VLCInputNode * const node in rootNode.children) {
+                [locationMrls addObject:node.inputItem.MRL];
+            }
         }
     }
 


=====================================
modules/gui/macosx/library/media-source/VLCMediaSourceBaseDataSource.m
=====================================
@@ -211,6 +211,10 @@ NSString * const VLCMediaSourceBaseDataSourceNodeChanged = @"VLCMediaSourceBaseD
     if (_mediaSourceMode == VLCMediaSourceModeLAN) {
         VLCInputNode * const rootNode = mediaSource.rootNode;
         NSArray * const nodeChildren = rootNode.children;
+        if (nodeChildren == nil) {
+            NSLog(@"No children found for media source root node: %@ cannot provide viewItem correctly", rootNode);
+            return viewItem;
+        }
         VLCInputNode * const childNode = nodeChildren[indexPath.item];
         VLCInputItem * const childRootInput = childNode.inputItem;
         viewItem.titleTextField.stringValue = childRootInput.name;
@@ -274,6 +278,10 @@ NSString * const VLCMediaSourceBaseDataSourceNodeChanged = @"VLCMediaSourceBaseD
         mediaSource = _mediaSources[indexPath.section];
         VLCInputNode * const rootNode = mediaSource.rootNode;
         NSArray * const nodeChildren = rootNode.children;
+        if (nodeChildren == nil) {
+            NSLog(@"No children found for media source root node: %@ cannot access item correctly", rootNode);
+            return;
+        }
         childNode = nodeChildren[indexPath.item];
     } else {
         mediaSource = _mediaSources[indexPath.item];


=====================================
modules/gui/macosx/library/media-source/VLCMediaSourceDataSource.m
=====================================
@@ -120,11 +120,11 @@ NSString * const VLCMediaSourceDataSourceNodeChanged = @"VLCMediaSourceDataSourc
     [self.tableView setTarget:self];
 }
 
-- (VLCInputNode *)inputNodeForIndexPath:(NSIndexPath *)indexPath
+- (nullable VLCInputNode *)inputNodeForIndexPath:(NSIndexPath *)indexPath
 {
     VLCInputNode * const rootNode = self.nodeToDisplay;
     NSArray * const nodeChildren = rootNode.children;
-    return nodeChildren[indexPath.item];
+    return nodeChildren ? nodeChildren[indexPath.item] : nil;
 }
 
 - (NSArray<VLCInputItem *> *)mediaSourceInputItemsAtIndexPaths:(NSSet<NSIndexPath *> *const)indexPaths
@@ -134,6 +134,9 @@ NSString * const VLCMediaSourceDataSourceNodeChanged = @"VLCMediaSourceDataSourc
 
     for (NSIndexPath * const indexPath in indexPaths) {
         VLCInputNode * const inputNode = [self inputNodeForIndexPath:indexPath];
+        if (!inputNode) {
+            continue;
+        }
         VLCInputItem * const inputItem = inputNode.inputItem;
         [inputItems addObject:inputItem];
     }
@@ -165,6 +168,10 @@ NSString * const VLCMediaSourceDataSourceNodeChanged = @"VLCMediaSourceDataSourc
 
     VLCInputNode *rootNode = _nodeToDisplay;
     NSArray *nodeChildren = rootNode.children;
+    if (nodeChildren == nil) {
+        NSLog(@"No children for node %@, cannot provide correctly setup viewItem", rootNode);
+        return viewItem;
+    }
     VLCInputNode *childNode = nodeChildren[indexPath.item];
     VLCInputItem *childRootInput = childNode.inputItem;
 
@@ -184,7 +191,9 @@ NSString * const VLCMediaSourceDataSourceNodeChanged = @"VLCMediaSourceDataSourc
         return;
     }
     VLCInputNode * const childNode = [self inputNodeForIndexPath:indexPath];
-    [self performActionForNode:childNode allowPlayback:YES];
+    if (childNode) {
+        [self performActionForNode:childNode allowPlayback:YES];
+    }
 }
 
 - (NSSize)collectionView:(NSCollectionView *)collectionView
@@ -224,7 +233,9 @@ NSString * const VLCMediaSourceDataSourceNodeChanged = @"VLCMediaSourceDataSourc
     }
 
     VLCInputNode *childNode = [self mediaSourceInputNodeAtRow:selectedIndex];
-    [self performActionForNode:childNode allowPlayback:NO];
+    if (childNode) {
+        [self performActionForNode:childNode allowPlayback:NO];
+    }
 }
 
 - (void)tableViewAction:(id)sender
@@ -235,10 +246,12 @@ NSString * const VLCMediaSourceDataSourceNodeChanged = @"VLCMediaSourceDataSourc
     }
 
     VLCInputNode *childNode = [self mediaSourceInputNodeAtRow:selectedIndex];
-    [self performActionForNode:childNode allowPlayback:YES];
+    if (childNode) {
+        [self performActionForNode:childNode allowPlayback:YES];
+    }
 }
 
-- (VLCInputNode*)mediaSourceInputNodeAtRow:(NSInteger)tableViewRow
+- (nullable VLCInputNode *)mediaSourceInputNodeAtRow:(NSInteger)tableViewRow
 {
     if (_nodeToDisplay == nil) {
         return nil;


=====================================
modules/gui/macosx/playqueue/VLCPlaybackContinuityController.m
=====================================
@@ -157,6 +157,10 @@ static NSString *VLCRecentlyPlayedMediaListKey = @"recentlyPlayedMediaList";
 
     /* allow the user to over-write the start/stop/run-time */
     NSArray<NSString *> * const options = inputItem.options;
+    if (options == nil) {
+        return;
+    }
+
     const NSUInteger runtimeOption = [options indexOfObjectPassingTest:^BOOL(NSString * const obj, NSUInteger, BOOL *){
         return [obj hasPrefix:@"start-time"] || [obj hasPrefix:@"stop-time"];
     }];



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/567be20648eda24b09805984020fcd929bb8f104...dd316430ff334daf21e78ac51748f944063a668b

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/567be20648eda24b09805984020fcd929bb8f104...dd316430ff334daf21e78ac51748f944063a668b
You're receiving this email because of your account on code.videolan.org.


VideoLAN code repository instance


More information about the vlc-commits mailing list