Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

[mob][photos] Skip ML JPEG fallback for RAW decode failures

laurenspriemb60ef8975206
diff --git a/mobile/apps/photos/lib/ui/viewer/file/zoomable_image.dart b/mobile/apps/photos/lib/ui/viewer/file/zoomable_image.dart
index 1fa4bc43f9..7b5d1b3505 100644
--- a/mobile/apps/photos/lib/ui/viewer/file/zoomable_image.dart
+++ b/mobile/apps/photos/lib/ui/viewer/file/zoomable_image.dart
@@ -481,27 +481,7 @@ class _ZoomableImageState extends State<ZoomableImage> {
bool _isRawFile() {
final extension = _photo.displayName.toLowerCase().split('.').last;
- const rawExtensions = {
- 'arw', // Sony
- 'cr2', 'cr3', // Canon
- 'nef', 'nrw', // Nikon
- 'dng', // Adobe/generic
- 'orf', // Olympus
- 'raf', // Fuji
- 'rw2', // Panasonic
- 'pef', // Pentax
- 'srw', // Samsung
- '3fr', 'fff', // Hasselblad
- 'rwl', // Leica
- 'x3f', // Sigma
- 'iiq', // Phase One
- 'kdc', 'dcr', // Kodak
- 'mrw', // Minolta
- 'erf', // Epson
- 'mef', // Mamiya
- 'raw', // Generic
- };
- return rawExtensions.contains(extension);
+ return isRawImageExtension(extension);
}
Future<void> _loadInSupportedFormat(
diff --git a/mobile/apps/photos/lib/utils/file_util.dart b/mobile/apps/photos/lib/utils/file_util.dart
index 0b77733713..80b28c62d8 100644
--- a/mobile/apps/photos/lib/utils/file_util.dart
+++ b/mobile/apps/photos/lib/utils/file_util.dart
@@ -23,6 +23,31 @@ import 'package:photos/utils/thumbnail_util.dart';
final _logger = Logger("FileUtil");
+const Set<String> _rawImageExtensions = {
+ 'arw', // Sony
+ 'cr2', 'cr3', // Canon
+ 'nef', 'nrw', // Nikon
+ 'dng', // Adobe/generic
+ 'orf', // Olympus
+ 'raf', // Fuji
+ 'rw2', // Panasonic
+ 'pef', // Pentax
+ 'srw', // Samsung
+ '3fr', 'fff', // Hasselblad
+ 'rwl', // Leica
+ 'x3f', // Sigma
+ 'iiq', // Phase One
+ 'kdc', 'dcr', // Kodak
+ 'mrw', // Minolta
+ 'erf', // Epson
+ 'mef', // Mamiya
+ 'raw', // Generic
+};
+
+bool isRawImageExtension(String extension) {
+ return _rawImageExtensions.contains(extension.toLowerCase());
+}
+
void preloadFile(EnteFile file) {
if (file.fileType == FileType.video) {
return;
diff --git a/mobile/apps/photos/lib/utils/image_ml_util.dart b/mobile/apps/photos/lib/utils/image_ml_util.dart
index 519593b41a..a1800de249 100644
--- a/mobile/apps/photos/lib/utils/image_ml_util.dart
+++ b/mobile/apps/photos/lib/utils/image_ml_util.dart
@@ -15,6 +15,7 @@ import 'package:photos/services/machine_learning/face_ml/face_alignment/alignmen
import 'package:photos/services/machine_learning/face_ml/face_alignment/similarity_transform.dart';
import 'package:photos/services/machine_learning/face_ml/face_detection/detection.dart';
import 'package:photos/services/machine_learning/face_ml/face_filtering/blur_detection_service.dart';
+import "package:photos/utils/file_util.dart";
/// All of the functions in this file are helper functions for using inside an isolate.
/// Don't use them outside of a isolate, unless you are okay with UI jank!!!!
@@ -81,6 +82,16 @@ Future<DecodedImage> decodeImageFromPath(
try {
image = await decodeImageFromData(imageData);
} catch (e, s) {
+ if (isRawImageExtension(format)) {
+ _logger.warning(
+ "Skipping JPEG conversion for RAW image format $format because flutter_image_compress is known to crash on unsupported RAW input",
+ e,
+ s,
+ );
+ throw Exception(
+ 'InvalidImageFormatException: Error decoding image of format $format',
+ );
+ }
_logger.info(
'Cannot decode $format on ${Platform.isAndroid ? "Android" : "iOS"}, converting to jpeg',
);
diff --git a/mobile/apps/photos/lib/utils/ml_util.dart b/mobile/apps/photos/lib/utils/ml_util.dart
index fd5e2309e5..d2bff9c7f0 100644
--- a/mobile/apps/photos/lib/utils/ml_util.dart
+++ b/mobile/apps/photos/lib/utils/ml_util.dart
@@ -752,6 +752,16 @@ Future<MLResult> analyzeImageRust(Map args) async {
e,
s,
);
+ if (_shouldSkipJpegDecodeFallback(fileFormat)) {
+ _logger.warning(
+ "Skipping JPEG fallback for fileID $enteFileID (format: $fileFormat) because flutter_image_compress is known to crash on unsupported RAW input",
+ );
+ throw _asInvalidImageFormatExceptionForRustDecodeFailure(
+ enteFileID: enteFileID,
+ fileFormat: fileFormat,
+ primaryError: e,
+ );
+ }
final _DecodeFallbackFile? fallback;
try {
fallback = await _createJpegDecodeFallbackFile(imagePath: imagePath);
@@ -927,6 +937,10 @@ bool _isRustDecodeIssue(Object error) {
return message.contains("decode error");
}
+bool _shouldSkipJpegDecodeFallback(String fileFormat) {
+ return isRawImageExtension(fileFormat);
+}
+
bool _shouldStoreEmptyResultForRustDecodeFailure({
required Object primaryError,
Object? fallbackError,
@@ -1041,6 +1055,12 @@ class _DecodeFallbackFile {
Future<_DecodeFallbackFile?> _createJpegDecodeFallbackFile({
required String imagePath,
}) async {
+ final format = getExtension(imagePath);
+ if (_shouldSkipJpegDecodeFallback(format)) {
+ throw Exception(
+ "InvalidImageFormatException: JPEG decode fallback skipped for unsupported RAW image format $format",
+ );
+ }
final convertedData = await FlutterImageCompress.compressWithFile(
imagePath,
format: CompressFormat.jpeg,