You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 0af6449
Browse filesBrowse the repository at this point in the historyBrowse files
Do not derive a decode size of 0 for very thin images (flutter#194669)
Fixesflutter#194668
A very thin image does not decode when the decode size is derived from
one side.
Example: a 4000x1 PNG with `cacheWidth: 100`. The derived height is
`100 ~/ 4000 = 0`, and the decode fails.
Observed on stable 3.47.7 (the same code is on master):
| Call (4000x1 or 1x4000 PNG) | Result |
| --- | --- |
| `Image.memory(..., cacheWidth: 100)` / `ResizeImage(width: 100)` |
`Exception: Codec failed to produce an image` (log: `Could not resize to
empty dimensions.`) |
| `ResizeImage(height: 100)` on 1x4000 | same exception |
| `ResizeImage(width: 100, policy: ResizeImagePolicy.fit)` (with or
without `allowUpscaling`, with or without `height`) | debug: the
assertion `height == null \|\| height > 0` (or `width == null \|\| width
> 0`) in `TargetImageSize` fails. By reading the code, in release mode
the 0 becomes null, `instantiateCodec` derives 0 again, and the codec
fails. |
| `ImageDescriptor.instantiateCodec(targetWidth: 100)` /
`ui.instantiateImageCodec(targetWidth: 100)` | same exception |
This change clamps each derived side to at least 1 pixel:
* `ImageDescriptor.instantiateCodec` in `dart:ui`
(`lib/ui/painting.dart`).
This is the path for `cacheWidth` or `cacheHeight` with one side, and
for
`instantiateImageCodec` with one target side.
* `scaledImageSize` in the web engine, which has the same derivation.
* `ResizeImage` with `ResizeImagePolicy.fit`. The clamp is on each side
that
a branch derives from the aspect ratio.
A side that the caller gives is not changed, so an explicit 0 still
fails at
decode time, as before, and is not changed to 1. `useLogicalSize` uses
`ceil`, so it cannot give 0.
## Tests
*
`packages/flutter/test/painting/image_provider_resize_image_test.dart`:
4000x1 and 1x4000 images with `policy: fit` decode to 100x1 and 1x100.
This test fails without the change (assertion in `TargetImageSize`) and
passes with it. The painting, image and fade tests pass locally.
*
`packages/flutter/test/painting/image_provider_resize_image_test.dart`:
`ResizeImage` with `width` or `height` of 0 still fails to decode with
`policy: exact` and `policy: fit`.
* `engine/src/flutter/testing/dart/codec_test.dart`:
`instantiateImageCodec(targetWidth: 100)` on 4000x1 gives 100x1, and
`targetHeight: 100` on 1x4000 gives 1x100.
* `engine/src/flutter/lib/web_ui/test/ui/image_test.dart`:
`scaledImageSize`
returns 100x1 and 1x100 for the same inputs.
I did not build the engine locally, so the `codec_test.dart` and web
tests run
only in CI.
## Pre-launch Checklist
- [x] I read the [Contributor Guide] and followed the process outlined
there for submitting PRs.
- [x] I read the [Tree Hygiene] wiki page, which explains my
responsibilities.
- [x] I read and followed the [Flutter Style Guide], including [Features
we expect every widget to implement].
- [x] I signed the [CLA].
- [x] I listed at least one issue that this PR fixes in the description
above.
- [ ] I updated/added relevant documentation (doc comments with `///`).
No doc change is necessary.
- [x] I added new tests to check the change I am making, or this PR is
[test-exempt].
- [ ] All existing and new tests are passing. The framework tests pass
locally. The engine and web tests run only in CI.
[Contributor Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview
[Tree Hygiene]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md
[test-exempt]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests
[Flutter Style Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md
[Features we expect every widget to implement]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement
[CLA]: https://cla.developers.google.com/
0 commit comments