react / react/react-native

React 74.5: loading images from data: URIs fails on iOS 15, works on 18

オープン
#48,494 コメント 2 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

Component: Image Issue: Author Provided Repro Newer Patch Available Platform: iOS
主要言語
C++
スター
127k
フォーク
25.3k
平均マージ
1日 23時間
マージ済み PR(30日)
4

説明

Description

I think this is related to: https://github.com/facebook/react-native/issues/42234
I tried reproducing it in the Expo Stack, but was not able to do it with the example on the website (https://reactnative.dev/docs/image#src). I can only presume this is because this happens in a native component.
Here is my code that is as close as possible to the error:

            console.log(`image: ${image.substring(0, 50)}...`),
            <TouchableOpacity key={imgIndex} onPress={() => { setSelectedImage(image); setSelectedFileName(fileName); }}>
              <Image source={{ uri: image }} style={globalStyles.imageThumbnail} onError={(error) => console.error(`${error} image: ${image.substring(image.length-50, image.length)}`)} />
            </TouchableOpacity>

Basically what causes the problem is that on iOS 15 (iphone 6s) the data uri that is being loaded by the Image component receives a .png at the end and a file:// at the beginning. As seen here (this is the warning that is presented to me, I think it comes from the component)
image
And this is the console output (note the warning text with the base64 encoded image data ending with .png, whereas the uri parameter given to the Image component does not have it):

rarKc0szkF5Bp5VemorXUBIcBJkhGhB2NwDc7/teeZ7DaCF52NMLw9Ks9AsOHPx%0D%0A58aFAJoJFGcCqwY+56o4C88CtPBMtlNg9TerPI95m2m20gM0IA08V+W5qc9A9ByA%0D%0A9n3gcQCY90iFZ33TVbWu4Ox4Hjyzv77O2PjrBNDCGUpyVZpVn8312JjqXPfdzQBd%0D%0A4RlVl23sHCrQLCgkKG9XFxRuH8raNYiO/xl4FqBRobnht6wdn6l5EM3fzr+l/5s+%0D%0AL4Jnji0D6P8HoPs5K+6F5G8AAAAASUVORK5CYII=.png
 ERROR  [object Object] image: zr+l/5s+
L4Jnji0D6P8HoPs5K+6F5G8AAAAASUVORK5CYII=

On iOS 18 this behavior (adding png and file) does not get triggered.

Edit:
I did some digging, and the function that shows the Could not find image warning from the screenshot, which already contains the malformed URI, does not even get triggered on the newer iOS version. To test this, I adjusted the code for both locations where the error is triggered:

- (nullable RCTImageLoaderCancellationBlock)loadImageForURL:(NSURL *)imageURL
                                                       size:(CGSize)size
                                                      scale:(CGFloat)scale
                                                 resizeMode:(RCTResizeMode)resizeMode
                                            progressHandler:(RCTImageLoaderProgressBlock)progressHandler
                                         partialLoadHandler:(RCTImageLoaderPartialLoadBlock)partialLoadHandler
                                          completionHandler:(RCTImageLoaderCompletionBlock)completionHandler
{
  UIImage *image = RCTImageFromLocalAssetURL(imageURL);
  NSString *message = [NSString stringWithFormat:@"CHANGED2_LOGCould not find image %@", imageURL];
  RCTLogWarn(@"%@", message);
  if (image) {
    if (progressHandler) {
      progressHandler(1, 1);
    }
    completionHandler(nil, image);
  } else {
    NSString *message = [NSString stringWithFormat:@"CHANGED2Could not find image %@", imageURL];
    RCTLogWarn(@"%@", message);
    completionHandler(RCTErrorWithMessage(message), nil);
  }

  return nil;
}

and

- (nullable RCTImageLoaderCancellationBlock)loadImageForURL:(NSURL *)imageURL
                                                       size:(CGSize)size
                                                      scale:(CGFloat)scale
                                                 resizeMode:(RCTResizeMode)resizeMode
                                            progressHandler:(RCTImageLoaderProgressBlock)progressHandler
                                         partialLoadHandler:(RCTImageLoaderPartialLoadBlock)partialLoadHandler
                                          completionHandler:(RCTImageLoaderCompletionBlock)completionHandler
{
  UIImage *image = RCTImageFromLocalAssetURL(imageURL);
  NSString *message = [NSString stringWithFormat:@"CHANGED_LOGCould not find image %@", imageURL];
  RCTLogWarn(@"%@", message);
  if (image) {
    if (progressHandler) {
      progressHandler(1, 1);
    }
    completionHandler(nil, image);
  } else {
    NSString *message = [NSString stringWithFormat:@"CHANGEDCould not find image %@", imageURL];
    RCTLogWarn(@"%@", message);
    completionHandler(RCTErrorWithMessage(message), nil);
  }

  return nil;
}

For reference, loadImageForURL is the one getting triggered on iOS 15, and no logs are generated on iOS 18.

Steps to reproduce

hand over data uri with base64 encoded image in <Image source={{ uri: image }}

React Native Version

0.74.5

Affected Platforms

Runtime - iOS

Output of npx react-native info
System:
  OS: macOS 15.1.1
  CPU: (14) arm64 Apple M4 Pro
  Memory: 202.11 MB / 48.00 GB
  Shell:
    version: "5.9"
    path: /bin/zsh
Binaries:
  Node:
    version: 23.3.0
    path: /opt/homebrew/bin/node
  Yarn: Not Found
  npm:
    version: 10.9.0
    path: /opt/homebrew/bin/npm
  Watchman:
    version: 2024.12.02.00
    path: /opt/homebrew/bin/watchman
Managers:
  CocoaPods:
    version: 1.16.2
    path: /opt/homebrew/bin/pod
SDKs:
  iOS SDK:
    Platforms:
      - DriverKit 24.2
      - iOS 18.2
      - macOS 15.2
      - tvOS 18.2
      - visionOS 2.2
      - watchOS 11.2
  Android SDK:
    API Levels:
      - "25"
      - "33"
      - "34"
    Build Tools:
      - 34.0.0
      - 35.0.0
    System Images:
      - android-24 | ARM 64 v8a
      - android-35 | Google Play ARM 64 v8a
    Android NDK: Not Found
IDEs:
  Android Studio: 2024.2 AI-242.23339.11.2421.12550806
  Xcode:
    version: 16.2/16C5032a
    path: /usr/bin/xcodebuild
Languages:
  Java:
    version: 17.0.13
    path: /usr/bin/javac
  Ruby:
    version: 2.6.10
    path: /usr/bin/ruby
npmPackages:
  "@react-native-community/cli": Not Found
  react:
    installed: 18.2.0
    wanted: 18.2.0
  react-native:
    installed: 0.74.5
    wanted: 0.74.5
  react-native-macos: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: true
  newArchEnabled: false
iOS:
  hermesEnabled: true
  newArchEnabled: false
Stacktrace or Logs
see in main message, but here:

rarKc0szkF5Bp5VemorXUBIcBJkhGhB2NwDc7/teeZ7DaCF52NMLw9Ks9AsOHPx%0D%0A58aFAJoJFGcCqwY+56o4C88CtPBMtlNg9TerPI95m2m20gM0IA08V+W5qc9A9ByA%0D%0A9n3gcQCY90iFZ33TVbWu4Ox4Hjyzv77O2PjrBNDCGUpyVZpVn8312JjqXPfdzQBd%0D%0A4RlVl23sHCrQLCgkKG9XFxRuH8raNYiO/xl4FqBRobnht6wdn6l5EM3fzr+l/5s+%0D%0AL4Jnji0D6P8HoPs5K+6F5G8AAAAASUVORK5CYII=.png
 ERROR  [object Object] image: zr+l/5s+
L4Jnji0D6P8HoPs5K+6F5G8AAAAASUVORK5CYII=


### Reproducer

https://snack.expo.dev/@btr/image-example

### Screenshots and Videos

_No response_

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

レポートで言及されているネイティブ iOS の loadImageForURL 実装と RCTImageFromLocalAssetURL から始めます。リンク先の Expo Snack にある data URI のケースを iOS 15 で再現し、iOS 18 と比較します。Image コンポーネントが file:// や .png を追加せずに URI を読み込めれば完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
ios, objective-c, react-native
領域
mobile
issue の種類
バグ
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
説明が足りない
初心者へのやさしさ
35/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。