Fix macOS StorageProvider null pointer bugs by NathanDrake2406 · Pull Request #21115 · AvaloniaUI/Avalonia (original) (raw)

added 2 commits

April 9, 2026 13:07

@NathanDrake2406

The null check on line 401 tested fileUri instead of filePathUri, making it dead code since fileUri was already checked on line 394. When [fileUri filePathURL] returned nil (non-file URL or unreachable resource), the nil filePathUri was passed to [filePathUri absoluteString] and then to CreateAvnString, causing a native crash.

@NathanDrake2406

NSError* was declared without initialization, containing stack garbage. On the success path (bookmarkData non-nil), Cocoa does not guarantee zeroing the error out-parameter, so the subsequent if (error != nil) check could read garbage and incorrectly call CreateAvnString with a garbage pointer.

Initialize to nil and restructure to else if so the error is only inspected when bookmarkData is nil (the failure path).

Copilot AI review requested due to automatic review settings

April 9, 2026 03:19

@NathanDrake2406

@NathanDrake2406

Initialize *ppv to nullptr on entry so callers never read garbage on the nil-fileUri / nil-bookmarkData paths. Guard *err write with a nullptr check for callers that pass no error out-parameter.

@NathanDrake2406

@MrJul

Merged via the queue into AvaloniaUI:master with commit 351e627

Apr 9, 2026

10 checks passed

MrJul added a commit to MrJul/Avalonia that referenced this pull request

Apr 13, 2026

@NathanDrake2406 @MrJul

The null check on line 401 tested fileUri instead of filePathUri, making it dead code since fileUri was already checked on line 394. When [fileUri filePathURL] returned nil (non-file URL or unreachable resource), the nil filePathUri was passed to [filePathUri absoluteString] and then to CreateAvnString, causing a native crash.

NSError* was declared without initialization, containing stack garbage. On the success path (bookmarkData non-nil), Cocoa does not guarantee zeroing the error out-parameter, so the subsequent if (error != nil) check could read garbage and incorrectly call CreateAvnString with a garbage pointer.

Initialize to nil and restructure to else if so the error is only inspected when bookmarkData is nil (the failure path).

Initialize *ppv to nullptr on entry so callers never read garbage on the nil-fileUri / nil-bookmarkData paths. Guard *err write with a nullptr check for callers that pass no error out-parameter.


Co-authored-by: Julien Lebosquain julien@lebosquain.net

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters

[ Show hidden characters]({{ revealButtonHref }})