Skip to content

ComputeCurrentStyle stack-overflows for translate values through CssAnyValue converter re-entry #243

Description

@sebastienros

Description

AngleSharp.Css 1.1.0 stack-overflows when computing the style of an element with a valid CSS individual transform property such as translate: 1px.

The failure reproduces with AngleSharp alone: no Jint, JavaScript, custom properties, Scalar, or variable dependency cycles are involved.

Versions

  • AngleSharp: 1.8.0
  • AngleSharp.Css: 1.1.0
  • .NET 10.0
  • Also relevant to the current source implementation unless already changed

Minimal reproduction

using AngleSharp;
using AngleSharp.Css.Dom;

var context = BrowsingContext.New(Configuration.Default.WithCss());
var document = await context.OpenAsync(request => request.Content(
    "<html><body><div style='translate: 1px'></div></body></html>"));

var element = document.QuerySelector("div")!;
var style = element.ComputeCurrentStyle();

Console.WriteLine(style.GetPropertyValue("translate"));

Project references:

<PackageReference Include="AngleSharp" Version="1.8.0" />
<PackageReference Include="AngleSharp.Css" Version="1.1.0" />

Actual behavior

The process exits with a stack overflow. The repeating native/.NET stack contains:

CssAnyValue.Compute
IdentifierValueConverter.Convert
OrValueConverter.Convert
CssAnyValue.Compute
...

A complete standalone reproduction and failure log are available from the investigation that found this issue.

Root cause

The translate property converter is shaped as an OrValueConverter combining none with AnyValueConverter. CssAnyValue.Compute avoids reparsing only when context.Converter is directly an AnyValueConverter.

When the converter is the composite OrValueConverter, Compute reparses the unchanged text through that same composite converter. The AnyValueConverter arm produces another unresolved CssAnyValue, and Compute(context) is immediately invoked again with the same composite converter, causing unbounded converter re-entry.

RotateConverter and ScaleConverter use the same converter shape and may be affected as well.

This is distinct from custom-property dependency-cycle handling such as #242. The reparsing branch predates that fix.

Expected behavior

ComputeCurrentStyle() should terminate and return the computed value for valid translate, rotate, and scale declarations. Composite converters containing an AnyValueConverter must not recursively reparse an unresolved CssAnyValue with the same converter indefinitely.

Suggested coverage

  • translate: 1px
  • valid two- and three-component translate forms
  • translate: none
  • corresponding valid rotate and scale forms
  • unresolved/invalid values retain existing error behavior
  • ordinary composite converters that resolve to concrete values continue computing normally
  • custom-property cycle coverage remains unchanged

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions