Skip to content

armgit / ente

Public Imported from GitHub
0

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

[mob][photos] Handle malformed gallery dimensions

ashil-pilot30760059f78e
diff --git a/mobile/apps/photos/lib/models/file/file.dart b/mobile/apps/photos/lib/models/file/file.dart
index d72aec7091..af38403ed1 100644
--- a/mobile/apps/photos/lib/models/file/file.dart
+++ b/mobile/apps/photos/lib/models/file/file.dart
@@ -227,12 +227,23 @@ class EnteFile {
} else {
// Gallery layout only needs these two fields. Decode them without
// materializing and retaining PubMagicMetadata for every gallery file.
- final metadata = jsonDecode(pubMmdEncodedJson ?? '{}');
- if (metadata is Map<String, dynamic>) {
- _width =
- PubMagicMetadata.safeParseInt(metadata[widthKey], widthKey) ?? 0;
- _height =
- PubMagicMetadata.safeParseInt(metadata[heightKey], heightKey) ?? 0;
+ _width = 0;
+ _height = 0;
+ try {
+ final metadata = jsonDecode(pubMmdEncodedJson ?? '{}');
+ if (metadata is Map<String, dynamic>) {
+ _width =
+ PubMagicMetadata.safeParseInt(metadata[widthKey], widthKey) ?? 0;
+ _height =
+ PubMagicMetadata.safeParseInt(metadata[heightKey], heightKey) ??
+ 0;
+ }
+ } on FormatException catch (error, stackTrace) {
+ _logger.severe(
+ "Failed to decode public metadata dimensions for file $tag",
+ error,
+ stackTrace,
+ );
}
}
_dimensionsDecoded = true;
diff --git a/mobile/apps/photos/test/models/gallery_groups_justified_test.dart b/mobile/apps/photos/test/models/gallery_groups_justified_test.dart
index 8725d7b3a4..0668b902e2 100644
--- a/mobile/apps/photos/test/models/gallery_groups_justified_test.dart
+++ b/mobile/apps/photos/test/models/gallery_groups_justified_test.dart
@@ -1,6 +1,7 @@
import "package:dio/dio.dart";
import "package:flutter/material.dart";
import "package:flutter_test/flutter_test.dart";
+import "package:logging/logging.dart";
import "package:package_info_plus/package_info_plus.dart";
import "package:photos/core/configuration.dart";
import "package:photos/core/constants.dart";
@@ -219,6 +220,40 @@ void main() {
);
});
+ test("malformed dimensions fall back to a square and log once", () async {
+ final logs = <LogRecord>[];
+ final subscription = Logger("File").onRecord.listen(logs.add);
+ try {
+ final file = EnteFile()
+ ..generatedID = 1
+ ..creationTime = DateTime(2026, 8, 19).microsecondsSinceEpoch
+ ..fileType = FileType.image
+ ..pubMmdEncodedJson = '{"w": 100';
+
+ final groups = _galleryGroups(
+ files: [file],
+ groupType: GroupType.none,
+ groupHeaderExtent: GalleryGroups.spacing,
+ );
+ final section = groups.groupLayouts.single as JustifiedSectionLayout;
+ final row = section.rows.single;
+
+ expect(row.itemWidths.single, row.height);
+ expect(
+ logs.where(
+ (record) =>
+ record.level == Level.SEVERE &&
+ record.message.contains(
+ "Failed to decode public metadata dimensions",
+ ),
+ ),
+ hasLength(1),
+ );
+ } finally {
+ await subscription.cancel();
+ }
+ });
+
test("file geometry survives replacement with the same stable identity", () {
final files = List<EnteFile>.generate(
20,