Skip to content

[image_picker] Fix If imageToScale is nil, the app will crash (#146682) #6514

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Apr 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/image_picker/image_picker_ios/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.8.10+1

* Fixes a possible crash when calling a picker method UIGraphicsImageRenderer if imageToScale is nil.

## 0.8.10

* Adds limit parameter to `MediaOptions` and `MultiImagePickerOptions` that sets a limit to how many media or image items can be selected.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,4 +217,24 @@ - (void)testScaledImage_WideImage_ShouldNotBeScaledAboveOriginaWidthOrHeight {
XCTAssertEqual(newImage.size.height, 7);
}

- (void)testScaledImage_ImageIsNil {
UIImage *image = nil;
UIImage *newImage = [FLTImagePickerImageUtil scaledImage:image
maxWidth:@1440
maxHeight:@1440
isMetadataAvailable:YES];

XCTAssertEqual(newImage, nil);
}

- (void)testScaledImage_ImageMaxWidthZeroAndMaxHeightIsZero {
UIImage *image = [UIImage imageWithData:ImagePickerTestImages.JPGTestData];
UIImage *newImage = [FLTImagePickerImageUtil scaledImage:image
maxWidth:@0
maxHeight:@0
isMetadataAvailable:YES];

XCTAssertEqual(newImage, nil);
}

@end
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ - (instancetype)initWithImages:(NSArray<UIImage *> *)images interval:(NSTimeInte
@implementation FLTImagePickerImageUtil : NSObject

static UIImage *FLTImagePickerDrawScaledImage(UIImage *imageToScale, double width, double height) {
if (imageToScale == nil || width == 0 || height == 0) {
return nil;
}
UIGraphicsImageRenderer *imageRenderer =
[[UIGraphicsImageRenderer alloc] initWithSize:CGSizeMake(width, height)
format:imageToScale.imageRendererFormat];
Expand Down
2 changes: 1 addition & 1 deletion packages/image_picker/image_picker_ios/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: image_picker_ios
description: iOS implementation of the image_picker plugin.
repository: https://github.com/flutter/packages/tree/main/packages/image_picker/image_picker_ios
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+image_picker%22
version: 0.8.10
version: 0.8.10+1

environment:
sdk: ^3.3.0
Expand Down