react / react/react-native

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

Abierto
#48,494 2 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Component: Image Issue: Author Provided Repro Newer Patch Available Platform: iOS
Lenguaje dominante
C++
Estrellas
127k
Forks
25.3k
Merge medio
1 d 23 h
PR fusionados (30 d)
4

Descripción

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_

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Línea de trabajo

Comienza con las implementaciones nativas de iOS de loadImageForURL y RCTImageFromLocalAssetURL mencionadas en el informe. Reproduce el caso de URI de datos del Expo Snack enlazado en iOS 15 y compáralo con iOS 18; se considera terminado cuando el componente Image carga la URI sin añadir file:// ni .png.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
ios, objective-c, react-native
Área
mobile
Tipo de issue
Error
Dificultad
4/5
Tiempo estimado
3-5 días
Estado de actividad
Estancado
Claridad
Necesita aclaración
Aptitud para principiantes
35/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.