Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sporadischer Index-Fehler #1

Closed
Bizarrus opened this issue May 16, 2020 · 4 comments
Closed

Sporadischer Index-Fehler #1

Bizarrus opened this issue May 16, 2020 · 4 comments

Comments

@Bizarrus
Copy link

Ich bekomme sporadisch immer Exceptions auf Zeile 163 geworfen:

buffer[i] = (byte) Convert.ToInt32(
	bits.Substring(
		bitCount - 8 < 0 ? 0 : bitCount - 8,
		bitCount - 8 < 0 ? bitCount : 8
	)
, 2);

StackTrace

System.ArgumentOutOfRangeException
  HResult=0x80131502
  Nachricht = Der Index lag außerhalb des Bereichs. Er darf nicht negativ und kleiner als die Sammlung sein.
Parametername: startIndex
  Quelle = mscorlib
  Stapelüberwachung:
   bei System.ParseNumbers.StringToInt(String s, Int32 radix, Int32 flags, Int32* currPos)
   bei System.Convert.ToInt32(String value, Int32 fromBase)
   bei Klass.Networking.Huffman.Compress(String pString) in C:\Users\adria\source\repos\Klass\Klass\Networking\Huffman.cs: Zeile4029
   bei KnuCli.Client.Send(Byte[] data, Boolean encode, Boolean compress) in C:\Users\adria\source\repos\Klass\KnuCli\Client.cs: Zeile105
   bei KnuCli.Client.Send(Byte[] data) in C:\Users\adria\source\repos\Klass\KnuCli\Client.cs: Zeile122
   bei KnuCli.UI.Login.SendLogin(String nickname, String password, String channel) in C:\Users\adria\source\repos\Klass\KnuCli\UI\Login.xaml.cs: Zeile56
   bei KnuCli.UI.Login.<Start>b__2_0(JObject data) in C:\Users\adria\source\repos\Klass\KnuCli\UI\Login.xaml.cs: Zeile45
   bei Klass.Helper.Password.Check(String nickname, String password, Action`1 callback) in C:\Users\adria\source\repos\Klass\Klass\Helper\Password.cs: Zeile34
   bei KnuCli.UI.Login.Start(Object sender, RoutedEventArgs e) in C:\Users\adria\source\repos\Klass\KnuCli\UI\Login.xaml.cs: Zeile32
   bei System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
   bei System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
   bei System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
   bei System.Windows.UIElement.RaiseEvent(RoutedEventArgs e)
   bei System.Windows.Controls.Primitives.ButtonBase.OnClick()
   bei System.Windows.Controls.Button.OnClick()
   bei System.Windows.Controls.Primitives.ButtonBase.OnMouseLeftButtonUp(MouseButtonEventArgs e)
   bei System.Windows.UIElement.OnMouseLeftButtonUpThunk(Object sender, MouseButtonEventArgs e)
   bei System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget)
   bei System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
   bei System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
   bei System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
   bei System.Windows.UIElement.ReRaiseEventAs(DependencyObject sender, RoutedEventArgs args, RoutedEvent newEvent)
   bei System.Windows.UIElement.OnMouseUpThunk(Object sender, MouseButtonEventArgs e)
   bei System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget)
   bei System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
   bei System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
   bei System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
   bei System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
   bei System.Windows.UIElement.RaiseTrustedEvent(RoutedEventArgs args)
   bei System.Windows.UIElement.RaiseEvent(RoutedEventArgs args, Boolean trusted)
   bei System.Windows.Input.InputManager.ProcessStagingArea()
   bei System.Windows.Input.InputManager.ProcessInput(InputEventArgs input)
   bei System.Windows.Input.InputProviderSite.ReportInput(InputReport inputReport)
   bei System.Windows.Interop.HwndMouseInputProvider.ReportInput(IntPtr hwnd, InputMode mode, Int32 timestamp, RawMouseActions actions, Int32 x, Int32 y, Int32 wheel)
   bei System.Windows.Interop.HwndMouseInputProvider.FilterMessage(IntPtr hwnd, WindowMessage msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
   bei System.Windows.Interop.HwndSource.InputFilterMessage(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
   bei MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
   bei MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
   bei System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
   bei System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
   bei System.Windows.Threading.Dispatcher.LegacyInvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
   bei MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
   bei MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg)
   bei System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
   bei System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame frame)
   bei System.Windows.Application.RunDispatcher(Object ignore)
   bei System.Windows.Application.RunInternal(Window window)
   bei System.Windows.Application.Run(Window window)
   bei System.Windows.Application.Run()
   bei KnuCli.App.Main()

Ich weiß echt nicht, wo da der Fehler liegt, denke aber mal, dass das ganze ein Encoding-Problem ist.

Bisher nutze ich das ganze erst für das Auth-Packet (n\0CHANNEL\0NICKNAME\0PASSWORD\0JOIN-TYPE).

@Bizarrus
Copy link
Author

Ich habe mal einen kleinen Test durchgeführt, der einfach Chars vom Integer hochzählt und durch Huffman jagt. Der scheint generell mit allen möglichen Zeichen probleme zu haben.

Warum ich hier extra alle Char-Sequenzen durchlaufen hat einen Sinn: Das GenericProtocol zum Beispiel beinhaltet genauso binäre Daten, dementsprechend kommt es hier auch zu Problemen. Die ConnectionInfo vom (-Paket hat genauso Binärdaten (PasswordHashing, PacketHashing) sowie auch das Login-Paket (n) mit dem gehashten Passwort.

static public void Main() {
			
		
			Console.WriteLine("Unit Test");
			
			new Thread(new ThreadStart(Test)).Start();
			
		}
		
		public static void Test() {
			Huffman h = new Huffman();
		
		int max = 1000;
			int index = 0;
					
			while(index < max) {
				Check(h, index++);
			}
		}
		
		public static void Check(Huffman h, int index) {
			try {
				byte[] result = h.Compress((char) index + "");			} catch(Exception e) {
					Console.WriteLine("Error on: " + index + "\n\t" + e.Message + "\n");
				}
		}

E28093FD-0164-4966-8195-26F4097AA249

@SeBiTM
Copy link
Owner

SeBiTM commented May 21, 2020

Der Fehler lag offenbar daran das ich immer 8 Bit Parts aus dem String nehmen wollte, es ist aber scheinbar doch möglich kleinere Bit Parts zu verwenden.
Hab das ganze mal geupdated in meinen Tests konnte ich den Fehler bisher nicht verursachen

@Bizarrus
Copy link
Author

Super, ich schaue mir das eben mal an!

@Bizarrus
Copy link
Author

Bis jetzt scheint's echt zu funktionieren, Dankeschön!

Hätte später sonst mal das Teil von Brainy angeschaut, da gefällt mir aber nicht der Stil 😄

Ich schließe hier im Anschluss, da das ganze dann wohl behoben ist.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants