mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
A division by zero happens if the shadow color is fully transparent, and
the NaNs are getting assigned to the RGB values of the paint color being
handed to the rrect shadow draw. This doesn't cause a problem when wide
gamut is off because NaN output ends up being interpreted as zero (thus
making the shadow output fully transparent black, which happens to be
the expected and correct result). However, when a wide gamut attachment
is present, the NaN output ends up being interpreted as a negative
value.
Reproduction app:
```dart
import 'package:flutter/material.dart';
void main() => runApp(const GeneralDialogApp());
class EvilPainter extends CustomPainter {
@override
void paint(Canvas canvas, Size size) {
final Rect rect = Offset.zero & size;
canvas.drawPaint(Paint()..color = Colors.white);
canvas.saveLayer(null, Paint()..blendMode = BlendMode.srcOver);
canvas.drawShadow(Path()..addRect(Rect.fromLTRB(100, 100, 300, 300)),
Colors.black54, 15, false);
canvas.drawShadow(Path()..addRect(Rect.fromLTRB(100, 100, 300, 300)),
Colors.black54, 15, false);
canvas.drawShadow(Path()..addRect(Rect.fromLTRB(100, 100, 300, 300)),
Colors.transparent, 15, false);
canvas.restore();
}
@override
bool shouldRepaint(EvilPainter oldDelegate) => false;
@override
bool shouldRebuildSemantics(EvilPainter oldDelegate) => false;
}
class GeneralDialogApp extends StatelessWidget {
const GeneralDialogApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
restorationScopeId: 'app',
home: CustomPaint(painter: EvilPainter()),
);
}
}
```
Before:

After:

Description
Flutter makes it easy and fast to build beautiful apps for mobile and beyond
androidapp-frameworkcross-platformdartdart-platformdesktopflutterflutter-packagefuchsiaioslinux-desktopmacosmaterial-designmobilemobile-developmentskiawebweb-frameworkwindows
2.5 GiB
Languages
Dart
75%
C++
16.5%
Objective-C++
2.9%
Java
2.8%
Objective-C
0.7%
Other
1.9%