Skip to content

[video_player]Invalid videoComposition may cause the app crash #151031

Open

Description

@lxhlzyh

Steps to reproduce

iOS 16.2, iphone14 Pro Max
In some cases, setting the wrong video composition parameter can cause the app to crash. I got a crash report, but I don't have the video to reproduce the problem.
https://github.com/flutter/packages/blob/6b024cab554c519c19a4e16f6a1142bb7b20681a/packages/video_player/video_player_avfoundation/darwin/video_player_avfoundation/Sources/video_player_avfoundation/FVPVideoPlayerPlugin.m#L294
It is possible to replicate the problem with the wrong parameter Settings, although this approach is not very appropriate
videoComposition.renderSize = CGSizeMake(1920, 0); // or other
item.videoComposition = videoComposition;

We should check the validity of the parameters here.I am not familiar with the code design of this plugin, and I am not clear about what kind of AVPlayer should be returned after getting an exception.We should deal with it.
https://github.com/flutter/packages/blob/6b024cab554c519c19a4e16f6a1142bb7b20681a/packages/video_player/video_player_avfoundation/darwin/video_player_avfoundation/Sources/video_player_avfoundation/FVPVideoPlayerPlugin.m#L211

Expected results

Application don't crashed.

Actual results

Application crashed.

Code sample

Code sample
[Paste your code here]

Screenshots or Video

Screenshots / Video demonstration

[Upload media here]

Logs

Logs
libc++abi: terminating with uncaught exception of type NSException
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[AVPlayerItem setVideoComposition:] video composition must have a positive renderSize'
terminating with uncaught exception of type NSException
CoreSimulator 857.14 - Device: iPhone 14 Pro Max (F24BF7F8-F42C-412B-B330-667120A94C13) - Runtime: iOS 16.2 (20C52) - DeviceType: iPhone 14 Pro Max

Last Exception Backtrace:
0   CoreFoundation                	0x18cb2cf20 __exceptionPreprocess + 164 (NSException.m:249)
1   libobjc.A.dylib               	0x1849de018 objc_exception_throw + 60 (objc-exception.mm:356)
2   AVFCore                       	0x19e46e0f4 -[AVPlayerItem setVideoComposition:] + 432 (AVPlayerItem.m:0)
3   video_player_avfoundation     	0x104e469d4 0x104e40000 + 27092
4   libdispatch.dylib             	0x1949d013c _dispatch_call_block_and_release + 32 (init.c:1530)
5   libdispatch.dylib             	0x1949d1dd4 _dispatch_client_callout + 20 (object.m:576)
6   libdispatch.dylib             	0x1949d9400 _dispatch_lane_serial_drain + 748 (queue.c:3900)
7   libdispatch.dylib             	0x1949d9f64 _dispatch_lane_invoke + 432 (queue.c:3991)
8   libdispatch.dylib             	0x1949e4cb4 _dispatch_root_queue_drain_deferred_wlh + 288 (queue.c:6998)
9   libdispatch.dylib             	0x1949e4528 _dispatch_workloop_worker_thread + 404 (queue.c:6592)
10  libsystem_pthread.dylib       	0x1e9983934 _pthread_wqthread + 288 (pthread.c:2696)
11  libsystem_pthread.dylib       	0x1e99800cc start_wqthread + 8 (:-1)

Thread 14 name:
Thread 14 Crashed:
0   libsystem_kernel.dylib        	0x00000001d5be742c __pthread_kill + 8 (:-1)
1   libsystem_pthread.dylib       	0x00000001e9986c0c pthread_kill + 268 (pthread.c:1721)
2   libsystem_c.dylib             	0x0000000194a8aba0 abort + 180 (abort.c:118)
3   libc++abi.dylib               	0x00000001e98a4ca4 abort_message + 132 (abort_message.cpp:78)
4   libc++abi.dylib               	0x00000001e9894e5c demangling_terminate_handler() + 348 (cxa_default_handlers.cpp:77)
5   libobjc.A.dylib               	0x00000001849f9e2c _objc_terminate() + 144 (objc-exception.mm:496)
6   libc++abi.dylib               	0x00000001e98a4068 std::__terminate(void (*)()) + 16 (cxa_handlers.cpp:59)
7   libc++abi.dylib               	0x00000001e98a400c std::terminate() + 108 (cxa_handlers.cpp:88)
8   libdispatch.dylib             	0x00000001949d1de8 _dispatch_client_callout + 40 (object.m:579)
9   libdispatch.dylib             	0x00000001949d9400 _dispatch_lane_serial_drain + 748 (queue.c:3900)
10  libdispatch.dylib             	0x00000001949d9f64 _dispatch_lane_invoke + 432 (queue.c:3991)
11  libdispatch.dylib             	0x00000001949e4cb4 _dispatch_root_queue_drain_deferred_wlh + 288 (queue.c:6998)
12  libdispatch.dylib             	0x00000001949e4528 _dispatch_workloop_worker_thread + 404 (queue.c:6592)
13  libsystem_pthread.dylib       	0x00000001e9983934 _pthread_wqthread + 288 (pthread.c:2696)
14  libsystem_pthread.dylib       	0x00000001e99800cc start_wqthread + 8 (:-1)

Flutter Doctor output

Doctor output
┌─────────────────────────────────────────────────────────┐
│ A new version of Flutter is available!                  │
│                                                         │
│ To update to the latest version, run "flutter upgrade". │
└─────────────────────────────────────────────────────────┘
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.7.12, on macOS 12.6 21G115 darwin-arm64, locale
    zh-Hans-CN)
[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.0)
[✓] Xcode - develop for iOS and macOS (Xcode 14.2)
[✗] Chrome - develop for the web (Cannot find Chrome executable at
    /Applications/Google Chrome.app/Contents/MacOS/Google Chrome)
    ! Cannot find Chrome. Try setting CHROME_EXECUTABLE to a Chrome executable.
[✓] Android Studio (version 2021.2)
[✓] IntelliJ IDEA Community Edition (version 2022.1.4)
[✓] VS Code (version 1.90.0)
[✓] Connected device (2 available)
HTTP Host availability check is taking a long time...[!] HTTP Host Availability
    ✗ HTTP host "https://maven.google.com/" is not reachable. Reason: An error
      occurred while checking the HTTP host: Operation timed out
    ✗ HTTP host "https://cloud.google.com/" is not reachable. Reason: An error
      occurred while checking the HTTP host: Operation timed out

! Doctor found issues in 2 categories.

Activity

  1. changed the title [-][Video player]Invalid videoComposition may cause the app crash[/-] [+][video_player]Invalid videoComposition may cause the app crash[/+] on Jun 29, 2024
  2. danagbemava-nc commented on Jul 1, 2024

    @danagbemava-nc
    Member

    Hi @lxhlzyh, do you know the type of video that causes this crash to occur? Do you also by any chance know the values that were passed that caused the crash?

  3. added
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Jul 1, 2024
  4. lxhlzyh commented on Jul 1, 2024

    @lxhlzyh
    Author

    Hi @lxhlzyh, do you know the type of video that causes this crash to occur? Do you also by any chance know the values that were passed that caused the crash?

    I don't know anything else about the video that led to the crash. The log shows that the crash occurred in AVPlayerItem setVideoComposition.However, there is also information about this in AVFoundation's AVPlayerItem.h.
    If the user provides relevant video information, I will be the first time to upload here.

  5. removed
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Jul 1, 2024
  6. danagbemava-nc commented on Jul 2, 2024

    @danagbemava-nc
    Member

    @lxhlzyh thanks for the update. One more thing, is there a more detailed crash log that you can share with us?

  7. added
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Jul 2, 2024
  8. lxhlzyh commented on Jul 2, 2024

    @lxhlzyh
    Author

    @lxhlzyh thanks for the update. One more thing, is there a more detailed crash log that you can share with us?

    @danagbemava-nc Sure, I updated the log entry above. You can see the crash backtrace and the thread stack.

  9. removed
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Jul 2, 2024
  10. danagbemava-nc commented on Jul 3, 2024

    @danagbemava-nc
    Member

    Labeling this based on the crash log provided above.

  11. added
    packageflutter/packages repository. See also p: labels.
    c: fatal crashCrashes that terminate the process
    and removed
    in triagePresently being triaged by the triage team
    on Jul 3, 2024
  12. 3 remaining items

  13. lxhlzyh commented on Jul 3, 2024

    @lxhlzyh
    Author

    Update, on macOS same.
    PR: flutter/packages#7050

  14. LouiseHsu commented on Jul 24, 2024

    @LouiseHsu
    Contributor

    @stuartmorgan is crashing the expected behavior when we pass in invalid parameters? if so maybe we should close this issue.

  15. stuartmorgan-g commented on Jul 24, 2024

    @stuartmorgan-g
    Contributor

    No, we should essentially never crash. If we can't prevent this case with input validation (it's unclear to me if this is bad client params, or bad video data), we should be catching the exception and sending the error back to the Dart side.

  16. added
    P2Important issues not at the top of the work list
    triaged-iosTriaged by iOS platform team
    on Jul 31, 2024
  17. florianthiel commented on May 9, 2025

    @florianthiel

    I have the same issue. But I am getting a video composition must have a positive frameDuration crash. The video is stored on Firebase storage and was created using Agora.io's MediaRecorder feature. I've attached a sample video that caused a crash. On Android everything is working fine.

    JaPOVUxtw1uwtySAhjim.mp4
  18. ananya-pathak-sndk commented on Sep 18, 2025

    @ananya-pathak-sndk

    Hi, I have a similar issue. And I am getting a video composition must have a positive frameDuration crash. Is their anyway we can handle this?

  19. HatsuneMikuV commented on Jan 27, 2026

    @HatsuneMikuV

    Any updates? Regarding the video composition must have a positive frameDuration crash issue.

    Demo:

    TestVideoCrashDemo.zip

    @stuartmorgan-g @danagbemava-nc

    Additionally, video_player_avfoundation 2.7.0 will not crash.

  20. neeraj-pilot commented on May 18, 2026

    @neeraj-pilot

    I have a concrete media sample and the track values for one reproducible case of this crash.

    Package/platform:

    • Package: video_player
    • Darwin implementation: video_player_avfoundation
    • Observed with video_player 2.10.0 and video_player_avfoundation 2.7.2
    • Platforms: iOS crash reported in app use; same Darwin code path reproduced locally on macOS

    Media type:

    Repro code:

    final controller = VideoPlayerController.file(File(pathToLsMp4));
    await controller.initialize();

    Actual result:

    The process aborts while initializing the controller:

    NSInvalidArgumentException
    *** -[AVPlayerItem setVideoComposition:] video composition must have a positive frameDuration

    The crashing path is:

    objc_exception_throw
    -[AVPlayerItem setVideoComposition:]
    video_player_avfoundation/FVPVideoPlayer.m
    item.videoComposition = videoComposition
    

    The relevant media values I observed from an AVFoundation probe:

    preferredTransform: non-identity rotation transform
    naturalSize: 1344x1008
    videoTrack.minFrameDuration: 0/90000
    

    CMTIME_IS_VALID(videoTrack.minFrameDuration) returns true for 0/90000, so the current code uses it here:

    if (CMTIME_IS_VALID(videoTrack.minFrameDuration)) {
      videoComposition.frameDuration = videoTrack.minFrameDuration;
    } else {
      videoComposition.frameDuration = CMTimeMake(1, 30);
    }

    However, 0/90000 is not a valid positive frame duration for AVMutableVideoComposition.frameDuration, and AVFoundation throws when the composition is assigned to the player item.

    I verified this with a small Objective-C AVFoundation repro that follows the same sequence as FVPVideoPlayer:

    1. Create AVURLAsset.
    2. Read the video track preferredTransform.
    3. Create AVMutableVideoComposition.
    4. Set videoComposition.frameDuration = videoTrack.minFrameDuration.
    5. Assign item.videoComposition = videoComposition.

    For the .LS.mp4 file this throws with the positive frameDuration exception. If the fallback is changed to treat zero duration as invalid, the same probe succeeds:

    CMTime frameDuration = videoTrack.minFrameDuration;
    if (CMTIME_IS_VALID(frameDuration) &&
        frameDuration.timescale > 0 &&
        frameDuration.value > 0) {
      videoComposition.frameDuration = frameDuration;
    } else {
      videoComposition.frameDuration = CMTimeMake(1, 30);
    }

    This looks like a more specific variant of this issue: the input is not a manually invalid render size, but real video metadata where minFrameDuration is a valid CMTime with a zero value.

    Relevant dependency versions from pubspec.lock:

      video_player:
        dependency: "direct main"
        description:
          name: video_player
          url: "https://pub.dev"
        source: hosted
        version: "2.10.0"
      video_player_avfoundation:
        dependency: transitive
        description:
          name: video_player_avfoundation
          url: "https://pub.dev"
        source: hosted
        version: "2.7.2"
      video_player_platform_interface:
        dependency: transitive
        description:
          name: video_player_platform_interface
          url: "https://pub.dev"
        source: hosted
        version: "6.4.0"
    

    Flutter doctor from the local macOS repro machine:

    [!] Flutter (Channel [user-branch], 3.32.8, on macOS 26.4 25E246 darwin-arm64, locale en-US)
        ! Flutter version 3.32.8 on channel [user-branch] at <local flutter checkout>
          Currently on an unknown channel. Run `flutter channel` to switch to an official channel.
          If that doesn't fix the issue, reinstall Flutter by following instructions at https://flutter.dev/setup.
        ! Upstream repository unknown source is not a standard remote.
          Set environment variable "FLUTTER_GIT_URL" to unknown source to dismiss this error.
        • Framework revision edada7c56e (10 months ago), 2025-07-25 14:08:03 +0000
        • Engine revision ef0cd00091
        • Dart version 3.8.1
        • DevTools version 2.45.1
    
    [!] Android toolchain - develop for Android devices (Android SDK version 36.1.0)
        • Android SDK at <local Android SDK path>
        ✗ cmdline-tools component is missing.
        ✗ Android license status unknown.
    
    [✓] Xcode - develop for iOS and macOS (Xcode 26.2)
        • Xcode at /Applications/Xcode.app/Contents/Developer
        • Build 17C52
        • CocoaPods version 1.16.2
    
    [✓] Chrome - develop for the web
        • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
    
    [✓] Android Studio (version 2025.2)
        • Android Studio at /Applications/Android Studio.app/Contents
        • Java version OpenJDK Runtime Environment (build 21.0.8+-14196175-b1038.72)
    
    [✓] IntelliJ IDEA Community Edition (version 2025.2.4)
        • IntelliJ at /Applications/IntelliJ IDEA CE.app
        • Flutter plugin version 88.0.0
        • Dart plugin version 252.25557.23
    
    [✓] VS Code (version 1.115.0)
        • VS Code at /Applications/Visual Studio Code.app/Contents
    
    [✓] Connected device (4 available)
        • iOS simulators
        • macOS (desktop) • macos • darwin-arm64 • macOS 26.4 25E246 darwin-arm64
        • Chrome (web)
    
    [✓] Network resources
        • All expected network resources are available.
    
    ! Doctor found issues in 2 categories.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work listc: fatal crashCrashes that terminate the processp: video_playerThe Video Player pluginpackageflutter/packages repository. See also p: labels.platform-iosiOS applications specificallyteam-iosOwned by iOS platform teamtriaged-iosTriaged by iOS platform team

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions