Skip to content

ScrollGestureRecognizer crashes long running application on 32-bit Linux #20858

@ondrejsusovsky

Description

@ondrejsusovsky

Describe the bug

When interacting with long running (25+ days) application on 32-bit Linux I get OverflowException with following stacktrace:

System.Private.CoreLib
   at System.OverflowException..ctor(String message)
   at System.TimeSpan.IntervalFromDoubleTicks(Double ticks)
   at Avalonia.Input.GestureRecognizers.ScrollGestureRecognizer.PointerPressed(PointerPressedEventArgs e)
   at Avalonia.Input.GestureRecognizers.GestureRecognizerCollection.HandlePointerPressed(PointerPressedEventArgs e)
   at Avalonia.Input.InputElement.<>c.<.cctor>b__32_13(InputElement x, PointerPressedEventArgs e)
   at Avalonia.Reactive.LightweightObservableBase`1.PublishNext(T value)
   at Avalonia.Interactivity.EventRoute.RaiseEventImpl(RoutedEventArgs e)
   at Avalonia.Interactivity.EventRoute.RaiseEvent(Interactive source, RoutedEventArgs e)
   at Avalonia.Interactivity.Interactive.RaiseEvent(RoutedEventArgs e)
   at Avalonia.Input.TouchDevice.ProcessRawEvent(RawInputEventArgs ev)
   at Avalonia.Controls.TopLevel.<>c.<HandleInput>b__150_0(Object state)
   at Avalonia.Threading.Dispatcher.Send(SendOrPostCallback action, Object arg, Nullable`1 priority)
   at Avalonia.Controls.TopLevel.HandleInput(RawInputEventArgs e)
   at Avalonia.ManualRawEventGrouperDispatchQueue.DispatchNext()
   at Avalonia.X11.X11PlatformThreading.RunLoop(CancellationToken cancellationToken)
   at Avalonia.Threading.DispatcherFrame.Run(IControlledDispatcherImpl impl)
   at Avalonia.Threading.Dispatcher.PushFrame(DispatcherFrame frame)
   at Avalonia.Threading.Dispatcher.MainLoop(CancellationToken cancellationToken)
   at Avalonia.Controls.ApplicationLifetimes.ClassicDesktopStyleApplicationLifetime.StartCore(String[] args)
   at Avalonia.ClassicDesktopStyleApplicationLifetimeExtensions.StartWithClassicDesktopLifetime(AppBuilder builder, String[] args, Action`1 lifetimeBuilder)
   at Appl.Program.Main(String[] args) 

To Reproduce

Let application containing ScrollGestureRecognizer run for 25 days and interact with it. Or pass events containing large enough timestamps to the ScrollGestureRecognizer.

Expected behavior

Not crash

Avalonia version

11.2.x, but looking at the code it should affect master also

OS

Linux

Additional context

Looking at it closer, it's two issues in one:

  1. Input event timestamps overflow after ~25 days, and negative values are converted to large ulong values
    Timestamp = (ulong)ev->time.ToInt64();
  2. Timestamps are converted to TimeSpans, which have limited range that doesn't allow these large overflowed UInt64 values
    _velocityTracker?.AddPosition(TimeSpan.FromMilliseconds(e.Timestamp), default);

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions