Skip to content

[image_picker_ios] Picking an iOS 26+ HDR screenshot (10-bit HEIF) returns a 0-byte file when maxWidth/maxHeight are set #193089

Closed
flutter/packages
#12998

Description

@technobibi

What package does this bug report belong to?

image_picker (image_picker_ios)

What target platforms are you seeing this bug on?

iOS

Have you already upgraded your packages?

Yes. Reproduced with image_picker_ios 0.8.13+6; 0.8.13+7 (latest on pub.dev) and main contain the same code in FLTImagePickerImageUtil.m.

Dependency versions

image_picker 1.2.3 / image_picker_ios 0.8.13+6 / image_picker_platform_interface 2.11.1

Steps to reproduce

  1. On an iPhone with an HDR display running iOS 26 or later, set Settings > General > Screen Capture > Format to HDR and take a screenshot. iOS saves it as HEIF (brand heix, 10-bit 4:4:4 HEVC, Display P3 with a PQ profile, ISO gain map) instead of PNG.
  2. In a Flutter app call ImagePicker().pickImage(source: ImageSource.gallery, maxWidth: 2048, maxHeight: 2048) and pick that screenshot.
  3. Read the returned XFile.

Verified on iPhone 15 Pro / iOS 27.0 (two different HDR screenshots). SDR screenshots (PNG) and HEIC camera photos from the same library work.

Expected results

A scaled JPEG/PNG, or a PlatformException if the image cannot be processed.

Actual results

pickImage resolves with a path to a 0-byte file, so the app treats the pick as successful and fails later when decoding. No error is reported.

Where it breaks (traced with os_log added to the plugin):

  • PHPickerResult is returned (types public.heic, public.png), loadDataRepresentation(public.image) yields 907,458 bytes.
  • [[UIImage alloc] initWithData:] succeeds (1179x2556) and CGImage is non-NULL.
  • FLTImagePickerImageUtil scaledImage: returns an image of size 0x0: the UIGraphicsImageRenderer created with imageToScale.imageRendererFormat in FLTImagePickerDrawScaledImage produces an empty image for this source.
  • UIImageJPEGRepresentation of the 0x0 image is nil, and FLTImagePickerPhotoAssetUtil createFile: writes the nil data as an empty file and still returns the path.

Without maxWidth/maxHeight the scaler is skipped and the pick works.

Code sample

final picked = await ImagePicker().pickImage(
  source: ImageSource.gallery,
  maxWidth: 2048,
  maxHeight: 2048,
);
final bytes = await picked!.readAsBytes();
print(bytes.length); // 0 for an iOS 26+ HDR screenshot

Screenshots or Videos

No response

Logs

Instrumented run on the device (os_log added around the existing steps):

didFinishPicking count=1
result types=("public.heic", "public.png", "com.apple.private.photos.thumbnail.standard", "com.apple.private.photos.thumbnail.low")
loadData bytes=907458 err=(null)
decode ok w=1179 h=2556 cg=ok
scaled ok w=0 h=0
saved bytes=0

Proposed fix (happy to open a PR against flutter/packages if you want it)

Verified on the same device:

  1. In FLTImagePickerDrawScaledImage, if the renderer built from imageToScale.imageRendererFormat returns an image whose size is 0x0, render again with an explicit format (UIGraphicsImageRendererFormat.defaultFormat, scale = 1, opaque = NO, preferredRange = UIGraphicsImageRendererFormatRangeStandard) and draw with [imageToScale drawInRect:]. This yields the expected 945x2048 image for the HDR screenshot and leaves other images on the existing path.
  2. Make createFile: return nil for empty data and have FLTPHPickerSaveImageToPathOperation complete with an invalid_image FlutterError when the saved path is nil, so a failed encode surfaces as an exception instead of a 0-byte file. (The UIImagePickerController paths wrap savedPath in an array literal, so they need the same nil guard.)

Flutter Doctor output

[✓] Flutter (Channel stable, 3.44.2, on macOS 26.5 25F71 darwin-arm64, locale ja-JP) [267ms]
    • Flutter version 3.44.2 on channel stable at /opt/homebrew/share/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision c9a6c48423 (3 months ago), 2026-06-10 15:52:41 -0700
    • Engine revision 77e2e94772
    • Dart version 3.12.2
    • DevTools version 2.57.0
    • Feature flags: enable-web, enable-linux-desktop, enable-macos-desktop, enable-windows-desktop, enable-android, enable-ios, cli-animations, enable-native-assets, no-enable-swift-package-manager, omit-legacy-version-file, no-enable-lldb-debugging, enable-uiscene-migration

[✓] Android toolchain - develop for Android devices (Android SDK version 37.0.0) [991ms]
    • Android SDK at /Users/techno-bibi/Library/Android/sdk
    • Emulator version 36.6.11.0 (build_id 15507667) (CL:N/A)

Activity

  1. added
    in triage
    on Sep 21, 2026
  2. mbcorona commented on Sep 21, 2026

    @mbcorona
    Member

    HI @technobibi , thanks for reporting. I was able to reproduce on:

    iPhone 15 Pro Max iOS 27
    Flutter 3.47.5
    image_picker 1.2.3

    Picking an HDR screenshot (Settings > General > Screen Capture > Format = HDR, then screenshot HDR content, saved as 10-bit HEIF):

    • with maxWidth/maxHeight 2048: readAsBytes() returns 0 bytes, path points at an empty file, no error.
    • same screenshot without limits: <FILL IN, e.g. 907458> bytes, header ff d8 ..., decodes fine.
    • a normal SDR screenshot with the same limits: non-zero, fine.

    So it is specific to the scaler on a 10-bit HDR source, matching the scaledImage 0x0 trace above.

    Minimal self contained repro (drop into a fresh flutter create, add image_picker to pubspec and NSPhotoLibraryUsageDescription to ios/Runner/Info.plist, run on a physical HDR iPhone):

    import 'dart:io';
    import 'dart:typed_data';
    import 'package:flutter/material.dart';
    import 'package:image_picker/image_picker.dart';
    
    void main() => runApp(const MaterialApp(home: HdrRepro()));
    
    class HdrRepro extends StatefulWidget {
      const HdrRepro({super.key});
      @override
      State<HdrRepro> createState() => _HdrReproState();
    }
    
    class _HdrReproState extends State<HdrRepro> {
      final ImagePicker _picker = ImagePicker();
      String _result = 'Pick the HDR screenshot.';
    
      Future<void> _pick({required bool withLimits}) async {
        final XFile? file = await _picker.pickImage(
          source: ImageSource.gallery,
          maxWidth: withLimits ? 2048 : null,
          maxHeight: withLimits ? 2048 : null,
        );
        if (file == null) return;
        final Uint8List bytes = await file.readAsBytes();
        final head = bytes.isEmpty
            ? '(none)'
            : bytes.take(4).map((b) => b.toRadixString(16).padLeft(2, '0')).join(' ');
        setState(() => _result =
            '${withLimits ? "with limits" : "no limits"}\n'
            'bytes: ${bytes.length}${bytes.isEmpty ? "  <-- empty" : ""}\n'
            'first bytes: $head\n'
            'exists: ${File(file.path).existsSync()}');
      }
    
      @override
      Widget build(BuildContext context) => Scaffold(
            appBar: AppBar(title: const Text('HDR 0-byte repro')),
            body: Padding(
              padding: const EdgeInsets.all(16),
              child: Column(crossAxisAlignment: CrossAxisAlignment.stretch, children: [
                FilledButton(
                    onPressed: () => _pick(withLimits: true),
                    child: const Text('Pick WITH maxWidth/maxHeight (repro)')),
                const SizedBox(height: 8),
                OutlinedButton(
                    onPressed: () => _pick(withLimits: false),
                    child: const Text('Pick WITHOUT limits (control)')),
                const SizedBox(height: 24),
                SelectableText(_result),
              ]),
            ),
          );
    }

    Routing to the iOS team for further investigation.

  3. added
    platform-ios
    package
    fyi-ecosystem
    team-ios
    and removed
    in triage
    on Sep 21, 2026
  4. okorohelijah commented on Sep 23, 2026

    @okorohelijah
    Contributor

    What this is: FLTImagePickerDrawScaledImage initializes UIGraphicsImageRenderer from imageToScale.imageRendererFormat, which fails on 10-bit wide-gamut sources (such as iOS 26 HDR HEIF screenshots) and causes FLTImagePickerPhotoAssetUtil to write a 0-byte temp file when maxWidth/maxHeight are set. This is the same root cause as #185623, which has an approved fix in flight in flutter/packages#12557.

    What I verified:

    What I could not verify: Runtime behavior on an iOS 26+ device or simulator — I am on a Linux host without Xcode.

    Confidence: Medium — the code path, Apple documentation, and in-flight PR flutter/packages#12557 align with both reports on this thread, though I could not execute the Objective-C scaler on iOS.

    To move this forward: @LouiseHsu / @hellohuanlin — should this issue be closed as a duplicate of #185623 once flutter/packages#12557 lands, or kept open to also guard +createFile:suffix: against nil image data?

    Pre-triage by Elijah's_triage_agent — verify before acting on it.

  5. hellohuanlin commented on Sep 24, 2026

    @hellohuanlin
    Contributor

    happy to open a PR against flutter/packages if you want it

    @technobibi yes PRs are always welcome!

  6. technobibi commented on Sep 24, 2026

    @technobibi
    Author

    I confirmed on an iPhone 15 Pro (iOS 27.0) that the HDR screenshot failure is fixed by flutter/packages#12557 (0.8.13+8).
    The 0-byte file part was still unfixed, so I opened flutter/packages#12998. It is verified on the device and covered by native tests. Please take a look when you have time.

  7. added
    P2
    triaged-ios
    on Sep 24, 2026
  8. added
    triaged-ecosystem
    on Sep 29, 2026
  9. removed
    fyi-ecosystem
    triaged-ecosystem
    on Oct 10, 2026
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

    P2packageplatform-iosteam-iostriaged-ios

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions