From 5b3920785a616e0b641bf82e8f3ab9fff25fdda5 Mon Sep 17 00:00:00 2001 From: sr55 Date: Thu, 14 Jun 2018 19:56:44 +0100 Subject: [PATCH] WinGui: Fix an integer overflow in the UI layer for the start/stop controls. Fixes #1327 --- .../HandBrakeWPF/Controls/TimeSpanBox.xaml.cs | 10 +++--- .../Converters/LongToIntConverter.cs | 34 +++++++++++++++++++ win/CS/HandBrakeWPF/HandBrakeWPF.csproj | 1 + .../Services/Encode/Model/EncodeTask.cs | 4 +-- .../HandBrakeWPF/Services/Scan/Model/Title.cs | 2 +- .../HandBrakeWPF/ViewModels/MainViewModel.cs | 12 ++++--- win/CS/HandBrakeWPF/Views/MainView.xaml | 5 +-- 7 files changed, 53 insertions(+), 15 deletions(-) create mode 100644 win/CS/HandBrakeWPF/Converters/LongToIntConverter.cs diff --git a/win/CS/HandBrakeWPF/Controls/TimeSpanBox.xaml.cs b/win/CS/HandBrakeWPF/Controls/TimeSpanBox.xaml.cs index 5f983a699..a8277ec3b 100644 --- a/win/CS/HandBrakeWPF/Controls/TimeSpanBox.xaml.cs +++ b/win/CS/HandBrakeWPF/Controls/TimeSpanBox.xaml.cs @@ -67,7 +67,7 @@ namespace HandBrakeWPF.Controls /// The number property. /// public static readonly DependencyProperty NumberProperty = DependencyProperty.Register( - "Number", typeof(int), typeof(TimeSpanBox), new PropertyMetadata(OnNumberChanged)); + "Number", typeof(long), typeof(TimeSpanBox), new PropertyMetadata(OnNumberChanged)); /// /// The show time span property. @@ -225,11 +225,11 @@ namespace HandBrakeWPF.Controls /// /// Gets or sets the number. /// - public int Number + public long Number { get { - return (int)this.GetValue(NumberProperty); + return (long)this.GetValue(NumberProperty); } set @@ -337,7 +337,7 @@ namespace HandBrakeWPF.Controls /// private void DecrementNumber() { - int newNumber; + long newNumber; if (this.AllowEmpty && this.Number == 0) { newNumber = Math.Min(this.Maximum, -this.Increment); @@ -416,7 +416,7 @@ namespace HandBrakeWPF.Controls /// private void IncrementNumber() { - int newNumber; + long newNumber; if (this.AllowEmpty && this.Number == 0) { newNumber = Math.Max(this.Minimum, this.Increment); diff --git a/win/CS/HandBrakeWPF/Converters/LongToIntConverter.cs b/win/CS/HandBrakeWPF/Converters/LongToIntConverter.cs new file mode 100644 index 000000000..97b44338e --- /dev/null +++ b/win/CS/HandBrakeWPF/Converters/LongToIntConverter.cs @@ -0,0 +1,34 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License. +// +// +// Defines the FullPathToFileNameConverter type. +// +// -------------------------------------------------------------------------------------------------------------------- + +namespace HandBrakeWPF.Converters +{ + using System; + using System.Globalization; + using System.Windows.Data; + + public class LongToIntConverter : IValueConverter + { + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + if (value != null && value is long && (long)value <= int.MaxValue) + { + long result = (long)value; + return (int)result; + } + + return (int)0; + } + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + throw new NotImplementedException(); + } + } +} diff --git a/win/CS/HandBrakeWPF/HandBrakeWPF.csproj b/win/CS/HandBrakeWPF/HandBrakeWPF.csproj index c366fe1c6..0196c7d91 100644 --- a/win/CS/HandBrakeWPF/HandBrakeWPF.csproj +++ b/win/CS/HandBrakeWPF/HandBrakeWPF.csproj @@ -157,6 +157,7 @@ + diff --git a/win/CS/HandBrakeWPF/Services/Encode/Model/EncodeTask.cs b/win/CS/HandBrakeWPF/Services/Encode/Model/EncodeTask.cs index f65cf6891..3efaada5d 100644 --- a/win/CS/HandBrakeWPF/Services/Encode/Model/EncodeTask.cs +++ b/win/CS/HandBrakeWPF/Services/Encode/Model/EncodeTask.cs @@ -184,12 +184,12 @@ namespace HandBrakeWPF.Services.Encode.Model /// /// Gets or sets StartPoint. /// - public int StartPoint { get; set; } + public long StartPoint { get; set; } /// /// Gets or sets EndPoint. /// - public int EndPoint { get; set; } + public long EndPoint { get; set; } #endregion diff --git a/win/CS/HandBrakeWPF/Services/Scan/Model/Title.cs b/win/CS/HandBrakeWPF/Services/Scan/Model/Title.cs index e60520fa7..d83b65f87 100644 --- a/win/CS/HandBrakeWPF/Services/Scan/Model/Title.cs +++ b/win/CS/HandBrakeWPF/Services/Scan/Model/Title.cs @@ -181,7 +181,7 @@ namespace HandBrakeWPF.Services.Scan.Model /// The Start Point (Chapters) /// The End Point (Chapters) /// A Timespan - public TimeSpan CalculateDuration(int startPoint, int endPoint) + public TimeSpan CalculateDuration(long startPoint, long endPoint) { IEnumerable chapers = this.Chapters.Where(c => c.ChapterNumber >= startPoint && c.ChapterNumber <= endPoint); diff --git a/win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs b/win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs index 76e3c026e..930f8c680 100644 --- a/win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs +++ b/win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs @@ -808,7 +808,7 @@ namespace HandBrakeWPF.ViewModels { get { - return this.CurrentTask.StartPoint; + return this.CurrentTask.Angle; } set @@ -826,12 +826,13 @@ namespace HandBrakeWPF.ViewModels /// /// Gets or sets SelectedStartPoint. /// - public int SelectedStartPoint + public long SelectedStartPoint { get { return this.CurrentTask.StartPoint; } + set { this.CurrentTask.StartPoint = value; @@ -857,12 +858,13 @@ namespace HandBrakeWPF.ViewModels /// /// Gets or sets SelectedEndPoint. /// - public int SelectedEndPoint + public long SelectedEndPoint { get { return this.CurrentTask.EndPoint; } + set { this.CurrentTask.EndPoint = value; @@ -2245,8 +2247,8 @@ namespace HandBrakeWPF.ViewModels // Update the Main Window this.NotifyOfPropertyChange(() => this.Destination); this.SelectedAngle = this.CurrentTask.Angle; - int start = this.CurrentTask.StartPoint; - int end = this.CurrentTask.EndPoint; + long start = this.CurrentTask.StartPoint; + long end = this.CurrentTask.EndPoint; this.SelectedPointToPoint = this.CurrentTask.PointToPointMode; // Force reset. this.SelectedStartPoint = start; this.SelectedEndPoint = end; diff --git a/win/CS/HandBrakeWPF/Views/MainView.xaml b/win/CS/HandBrakeWPF/Views/MainView.xaml index 049e31a28..6ef0673bc 100644 --- a/win/CS/HandBrakeWPF/Views/MainView.xaml +++ b/win/CS/HandBrakeWPF/Views/MainView.xaml @@ -19,6 +19,7 @@ +