Skip to content

[vector_graphics]Add Null Check for Image Retrieval in listener.dart's onDrawImage Function #9211

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 22 commits into from
Jun 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
bb591c3
Ensure to perform validity checks before using images, provide clear …
addcn-ai-10525 May 6, 2025
6645216
Enhance image handling by adding validity checks and clear error mess…
addcn-ai-10525 May 7, 2025
698ae0f
updated CHANGELOG.md
addcn-ai-10525 May 7, 2025
e228870
Added unit tests, Add test for AssertionError when using invalid imag…
addcn-ai-10525 May 7, 2025
5c3ac82
Merge branch 'main' into fix_168364
wyqlxf May 7, 2025
b18c1dd
Merge branch 'flutter:main' into fix_168364
wyqlxf May 7, 2025
cb58a2b
Merge branch 'main' into fix_168364
wyqlxf May 8, 2025
cf418e2
code format optimization
addcn-ai-10525 May 8, 2025
19b5da2
code format optimization
addcn-ai-10525 May 8, 2025
6ac7795
Merge branch 'main' into fix_168364
wyqlxf May 8, 2025
bb1ffcc
Merge branch 'main' into fix_168364
wyqlxf May 8, 2025
c9477ac
Merge branch 'main' into fix_168364
wyqlxf May 12, 2025
7af7428
Merge branch 'main' into fix_168364
wyqlxf May 13, 2025
59dcb07
Merge branch 'main' into fix_168364
wyqlxf May 15, 2025
07221c9
Merge branch 'main' into fix_168364
wyqlxf May 15, 2025
3af88b9
Merge branch 'main' into fix_168364
wyqlxf May 16, 2025
8d30496
Merge branch 'main' into fix_168364
wyqlxf May 19, 2025
179e35f
Merge branch 'main' into fix_168364
wyqlxf May 19, 2025
71dc85f
Merge remote-tracking branch 'origin/main' into fix_168364
addcn-ai-10525 May 22, 2025
cc20da0
Merge remote-tracking branch 'origin/main' into fix_168364
addcn-ai-10525 May 23, 2025
afe17a0
update version
addcn-ai-10525 May 23, 2025
9233b60
Merge branch 'main' into fix_168364
wyqlxf Jun 9, 2025
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
5 changes: 3 additions & 2 deletions packages/vector_graphics/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## NEXT
## 1.1.19

* Updates minimum supported SDK version to Flutter 3.27/Dart 3.6.
* Updates minimum supported SDK version to Flutter 3.24/Dart 3.5.
* Enhance image handling by adding validity checks and clear error messages for improved robustness and maintainability.

## 1.1.18

Expand Down
7 changes: 6 additions & 1 deletion packages/vector_graphics/lib/src/listener.dart
Original file line number Diff line number Diff line change
Expand Up @@ -773,7 +773,12 @@ class FlutterVectorGraphicsListener extends VectorGraphicsCodecListener {
@override
void onDrawImage(int imageId, double x, double y, double width, double height,
Float64List? transform) {
final Image image = _images[imageId]!;
final Image? image = _images[imageId];
assert(image != null,
'Invalid imageId: $imageId. Image not found in _images.');
if (image == null) {
return;
}
if (transform != null) {
_canvas.save();
_canvas.transform(transform);
Expand Down
2 changes: 1 addition & 1 deletion packages/vector_graphics/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: vector_graphics
description: A vector graphics rendering package for Flutter using a binary encoding.
repository: https://github.com/flutter/packages/tree/main/packages/vector_graphics
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+vector_graphics%22
version: 1.1.18
version: 1.1.19

environment:
sdk: ^3.6.0
Expand Down
12 changes: 12 additions & 0 deletions packages/vector_graphics/test/listener_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,18 @@ void main() {
expect(drawParagraph1.memberName, #drawParagraph);
expect((drawParagraph1.positionalArguments[1] as Offset).dx, 58);
});

test('should assert when imageId is invalid', () async {
final TestPictureFactory factory = TestPictureFactory();
final FlutterVectorGraphicsListener listener =
FlutterVectorGraphicsListener(
pictureFactory: factory,
);
listener.onImage(0, 0, base64.decode(bluePngPixel));
await listener.waitForImageDecode();
expect(() => listener.onDrawImage(2, 10, 10, 100, 100, null),
throwsAssertionError);
});
}

class TestPictureFactory implements PictureFactory {
Expand Down