Skip to content

RenderSliverPadding.padding setter does not validate incoming negative padding #187527

Description

@fallintoplace

Use case

RenderSliverPadding validates non-negative padding in its constructor, but its padding setter currently re-checks the existing field instead of the incoming value.

Problem

The setter currently does this:

assert(padding.isNonNegative);

That validates the old value, not the new one being assigned.

As a result, this can slip through the setter in debug mode:

final RenderSliverPadding renderSliverPadding = RenderSliverPadding(
  padding: EdgeInsets.zero,
);
renderSliverPadding.padding = const EdgeInsets.all(-1.0);

Expected behavior

Assigning negative padding through RenderSliverPadding.padding should fail the same way the constructor does.

Actual behavior

The setter assertion checks the current padding instead of the incoming value, so negative input is not rejected at the setter boundary.

Additional context

I opened a fix here:

The proposed change is just to validate value.isNonNegative and add a regression test.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P1High-priority issues at the top of the work listf: scrollingViewports, list views, slivers, etc.frameworkflutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onteam-frameworkOwned by Framework teamtriaged-frameworkTriaged by Framework teamwaiting for PR to land (fixed)A fix is in flight

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions