From dbf86d3875ed5530406e20bb6728cd4d6593d7a5 Mon Sep 17 00:00:00 2001 From: Albie Spriddell Date: Wed, 1 May 2024 11:28:27 +0100 Subject: [PATCH] revert GetIPv4AddressRanges/GetIPv6AddressRanges changes (incorrect struct alignment) --- .../Sources/LocationDbSource.cs | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/DragonFruit.OnionFruit.Web.Worker/Sources/LocationDbSource.cs b/DragonFruit.OnionFruit.Web.Worker/Sources/LocationDbSource.cs index 21ed936..927ff86 100644 --- a/DragonFruit.OnionFruit.Web.Worker/Sources/LocationDbSource.cs +++ b/DragonFruit.OnionFruit.Web.Worker/Sources/LocationDbSource.cs @@ -157,16 +157,15 @@ private static unsafe int BuildUnmanagedNetworkStructArray(ILocationDatabase net } } - private static unsafe NetworkAddressRangeInfo[] GetIPv4AddressRanges(IntPtr startPtr, nint length) + private static unsafe NetworkAddressRangeInfo[] GetIPv4AddressRanges(IntPtr start, nint length) { - var v4NetworkRanges = new NetworkAddressRangeInfo[length]; - var start = (IPv4NetworkRange*)startPtr; - Span v4AddressBytes = stackalloc byte[4]; + var v4NetworkRanges = new NetworkAddressRangeInfo[length]; for (var i = 0; i < length; i++) { - var entry = *(start + i); + var entry = *(IPv4NetworkRange*)(start + sizeof(IPv4NetworkRange) * i); + var startAddress = ParseAddress(v4AddressBytes, entry.start_address); var endAddress = ParseAddress(v4AddressBytes, entry.end_address); @@ -176,16 +175,15 @@ private static unsafe NetworkAddressRangeInfo[] GetIPv4AddressRanges(IntPtr star return v4NetworkRanges; } - private static unsafe NetworkAddressRangeInfo[] GetIPv6AddressRanges(IntPtr startPtr, nint length) + private static unsafe NetworkAddressRangeInfo[] GetIPv6AddressRanges(IntPtr start, nint length) { var v6NetworkRanges = new NetworkAddressRangeInfo[length]; - var start = (IPv4NetworkRange*)startPtr; - Span v6AddressBytes = stackalloc byte[16]; for (var i = 0; i < length; i++) { - var entry = *(start + i); + var entry = *(IPv6NetworkRange*)(start + sizeof(IPv6NetworkRange) * i); + var startAddress = ParseAddress(v6AddressBytes, entry.start_address); var endAddress = ParseAddress(v6AddressBytes, entry.end_address);