This repository was archived by the owner on Feb 25, 2025. It is now read-only.
File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -1939,12 +1939,13 @@ class Codec extends NativeFieldWrapperClass2 {
19391939 final Completer <FrameInfo > completer = Completer <FrameInfo >.sync ();
19401940 final String ? error = _getNextFrame ((_Image ? image, int durationMilliseconds) {
19411941 if (image == null ) {
1942- throw Exception ('Codec failed to produce an image, possibly due to invalid image data.' );
1942+ completer.completeError (Exception ('Codec failed to produce an image, possibly due to invalid image data.' ));
1943+ } else {
1944+ completer.complete (FrameInfo ._(
1945+ image: Image ._(image),
1946+ duration: Duration (milliseconds: durationMilliseconds),
1947+ ));
19431948 }
1944- completer.complete (FrameInfo ._(
1945- image: Image ._(image),
1946- duration: Duration (milliseconds: durationMilliseconds),
1947- ));
19481949 });
19491950 if (error != null ) {
19501951 throw Exception (error);
Original file line number Diff line number Diff line change @@ -34,6 +34,18 @@ void main() {
3434 );
3535 });
3636
37+ test ('getNextFrame fails with invalid data' , () async {
38+ Uint8List data = await _getSkiaResource ('flutter_logo.jpg' ).readAsBytes ();
39+ data = Uint8List .view (data.buffer, 0 , 4000 );
40+ final ui.Codec codec = await ui.instantiateImageCodec (data);
41+ try {
42+ await codec.getNextFrame ();
43+ fail ('exception not thrown' );
44+ } catch (e) {
45+ expect (e, exceptionWithMessage ('Codec failed' ));
46+ }
47+ });
48+
3749 test ('nextFrame' , () async {
3850 final Uint8List data = await _getSkiaResource ('test640x479.gif' ).readAsBytes ();
3951 final ui.Codec codec = await ui.instantiateImageCodec (data);
You can’t perform that action at this time.
0 commit comments