Skip to content

[CP-beta]Check for overflow when computing the pixel buffer size for an animated PNG frame#185620

Merged
auto-submit[bot] merged 1 commit into
flutter:flutter-3.44-candidate.0from
flutteractionsbot:cp-beta-79ab0aabbc8452461f115d18731138d403cad987
Apr 28, 2026
Merged

[CP-beta]Check for overflow when computing the pixel buffer size for an animated PNG frame#185620
auto-submit[bot] merged 1 commit into
flutter:flutter-3.44-candidate.0from
flutteractionsbot:cp-beta-79ab0aabbc8452461f115d18731138d403cad987

Conversation

@flutteractionsbot

@flutteractionsbot flutteractionsbot commented Apr 27, 2026

Copy link
Copy Markdown
Contributor

Issue Link:

What is the link to the issue this cherry-pick is addressing?

http://b/489180577

Impact Description:

Reliability improvement in the animated PNG decoder

Changelog Description:

Fixes a potential integer overflow that could happen when handling some animated PNG files.

Workaround:

Is there a workaround for this issue?

No

Risk:

What is the risk level of this cherry-pick?

  • Low
  • Medium
  • High

Test Coverage:

Are you confident that your fix is well-tested by automated tests?

  • Yes
  • No

Validation Steps:

What are the steps to validate that this fix works?

See http://b/489180577

@flutteractionsbot flutteractionsbot added the cp: review Cherry-picks in the review queue label Apr 27, 2026
@flutteractionsbot

Copy link
Copy Markdown
Contributor Author

@jason-simmons please fill out the PR description above, afterwards the release team will review this request.

@flutter-dashboard

Copy link
Copy Markdown

This pull request was opened from and to a release candidate branch. This should only be done as part of the official Flutter release process. If you are attempting to make a regular contribution to the Flutter project, please close this PR and follow the instructions at Tree Hygiene for detailed instructions on contributing to Flutter.

Reviewers: Use caution before merging pull requests to release branches. Ensure the proper procedure has been followed.

@github-actions github-actions Bot added the engine flutter/engine related. See also e: labels. label Apr 27, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a SafeMath class in the fml library to handle overflow-safe multiplication for size_t, uint32_t, and uint64_t types, and integrates it into APNGImageGenerator for safer buffer size calculations. Review feedback suggests using if constexpr in the mul method to avoid narrowing conversion warnings and notes that public members of the new class require documentation to comply with the style guide.

namespace fml {

size_t SafeMath::mul(size_t x, size_t y) {
return sizeof(size_t) == sizeof(uint64_t) ? mul64(x, y) : mul32(x, y);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The ternary operator here can lead to narrowing conversion warnings or errors on 64-bit systems because mul32 expects uint32_t arguments, and x and y are size_t (64-bit). Even though the branch is not taken at runtime, the compiler still checks the types. Using if constexpr ensures that only the relevant branch is compiled, avoiding these issues.

Suggested change
return sizeof(size_t) == sizeof(uint64_t) ? mul64(x, y) : mul32(x, y);
if constexpr (sizeof(size_t) == sizeof(uint64_t)) {
return mul64(x, y);
} else {
return mul32(x, y);
}


// Math operations that check for overflow.
// Based on Skia's SkSafeMath.
class SafeMath {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

According to the Flutter style guide, all public members should have documentation. Please add a documentation comment for the SafeMath class.

References
  1. All public members should have documentation. (link)

// Based on Skia's SkSafeMath.
class SafeMath {
public:
bool overflow_detected() const { return overflow_detected_; }

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

According to the Flutter style guide, all public members should have documentation. Please add a documentation comment for the overflow_detected method.

References
  1. All public members should have documentation. (link)

public:
bool overflow_detected() const { return overflow_detected_; }

size_t mul(size_t x, size_t y);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

According to the Flutter style guide, all public members should have documentation. Please add a documentation comment for the mul method.

References
  1. All public members should have documentation. (link)

@camsim99 camsim99 added CICD Run CI/CD cp: review Cherry-picks in the review queue and removed cp: review Cherry-picks in the review queue labels Apr 27, 2026
@camsim99 camsim99 added the autosubmit Merge PR when tree becomes green via auto submit App label Apr 28, 2026
@auto-submit auto-submit Bot merged commit c8cc698 into flutter:flutter-3.44-candidate.0 Apr 28, 2026
177 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

autosubmit Merge PR when tree becomes green via auto submit App CICD Run CI/CD cp: review Cherry-picks in the review queue engine flutter/engine related. See also e: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants