From 0c377e599c899845712c22da2d3470df98ab14a7 Mon Sep 17 00:00:00 2001 From: sr55 Date: Thu, 14 Jun 2018 19:56:44 +0100 Subject: WinGui: Fix an integer overflow in the UI layer for the start/stop controls. Fixes #1327 --- win/CS/HandBrakeWPF/Controls/TimeSpanBox.xaml.cs | 10 +++---- .../HandBrakeWPF/Converters/LongToIntConverter.cs | 34 ++++++++++++++++++++++ win/CS/HandBrakeWPF/HandBrakeWPF.csproj | 1 + .../Services/Encode/Model/EncodeTask.cs | 4 +-- win/CS/HandBrakeWPF/Services/Scan/Model/Title.cs | 2 +- win/CS/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 (limited to 'win/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 bbd1fb88d..3fe2ab917 100644 --- a/win/CS/HandBrakeWPF/HandBrakeWPF.csproj +++ b/win/CS/HandBrakeWPF/HandBrakeWPF.csproj @@ -132,6 +132,7 @@ + diff --git a/win/CS/HandBrakeWPF/Services/Encode/Model/EncodeTask.cs b/win/CS/HandBrakeWPF/Services/Encode/Model/EncodeTask.cs index e1f18fd22..c40c6c0b9 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 31b6a1fe7..144a1ed26 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 9548fb573..11960ec39 100644 --- a/win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs +++ b/win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs @@ -811,7 +811,7 @@ namespace HandBrakeWPF.ViewModels { get { - return this.CurrentTask.StartPoint; + return this.CurrentTask.Angle; } set @@ -829,12 +829,13 @@ namespace HandBrakeWPF.ViewModels /// /// Gets or sets SelectedStartPoint. /// - public int SelectedStartPoint + public long SelectedStartPoint { get { return this.CurrentTask.StartPoint; } + set { this.CurrentTask.StartPoint = value; @@ -860,12 +861,13 @@ namespace HandBrakeWPF.ViewModels /// /// Gets or sets SelectedEndPoint. /// - public int SelectedEndPoint + public long SelectedEndPoint { get { return this.CurrentTask.EndPoint; } + set { this.CurrentTask.EndPoint = value; @@ -2306,8 +2308,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 9a45bfdd5..2bc3929cc 100644 --- a/win/CS/HandBrakeWPF/Views/MainView.xaml +++ b/win/CS/HandBrakeWPF/Views/MainView.xaml @@ -19,6 +19,7 @@ +