Skip to content

Commit 25bf1d2

Browse files
release v1.0.5
- [fix] fix potential overflow in receiving
1 parent 3383d9e commit 25bf1d2

File tree

4 files changed

+48
-21
lines changed

4 files changed

+48
-21
lines changed

.github/workflows/dotnet.yml

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -138,18 +138,11 @@ jobs:
138138
6.0.x
139139
2.1.x
140140
141-
# Restore dependencies
142-
- name: Restore dependencies
143-
run: dotnet restore
144-
145-
# Build the solution
146-
- name: Build solution
147-
run: dotnet build --configuration Release /p:OutputPath=../artifacts
148-
149141
# Push NuGet packages
150142
- name: Push NuGet Packages
151143
run: |
152144
echo "Current directory: $(pwd)"
153-
for package in ./artifacts/*.nupkg; do
154-
dotnet nuget push "$package" --api-key ${{ secrets.MYTOKEN }} --source https://api.nuget.org/v3/index.json
145+
dotnet pack Miku.Core/Miku.Core.csproj -c Release
146+
for package in $(find ./Miku.Core/bin/Release -name "*.nupkg" -print0 | sort -z -u | xargs -0 -n1 echo); do
147+
dotnet nuget push "$package" --api-key ${{ secrets.MYTOKEN }} --source https://api.nuget.org/v3/index.json --skip-duplicate
155148
done

Miku.Core/.AssemblyAttributes

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// <autogenerated />
2+
using System;
3+
using System.Reflection;
4+
[assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]

Miku.Core/Miku.Core.csproj

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<ImplicitUsings>disable</ImplicitUsings>
55
<Nullable>disable</Nullable>
66
<LangVersion>9</LangVersion>
7-
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
7+
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
88
<Version>1.0.4</Version>
99
<PackageId>Miku</PackageId>
1010
<Title>Miku</Title>
@@ -14,24 +14,40 @@
1414
<PackageProjectUrl>https://github.com/JasonXuDeveloper/Miku</PackageProjectUrl>
1515
<RepositoryUrl>https://github.com/JasonXuDeveloper/Miku</RepositoryUrl>
1616
<RepositoryType>git</RepositoryType>
17-
<PackageTags>ECS</PackageTags>
17+
<PackageTags>TCP;Networking;High-Perofrmance</PackageTags>
1818
<PackageLicenseExpression>MIT</PackageLicenseExpression>
1919
<PackageReadmeFile>README.md</PackageReadmeFile>
2020
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
2121
<BranchName>refs/heads/main</BranchName>
22+
<TargetFrameworks>net6.0;netstandard2.1;</TargetFrameworks>
2223
<PublishRepositoryUrl>true</PublishRepositoryUrl>
2324
<EmbedUntrackedSources>true</EmbedUntrackedSources>
24-
<TargetFrameworks>net6.0;netstandard2.1;</TargetFrameworks>
25+
<IncludeSource>true</IncludeSource>
26+
<DebugType>embedded</DebugType>
27+
<GenerateAssemblyInfo>true</GenerateAssemblyInfo>
28+
</PropertyGroup>
29+
30+
<!-- for .NET Standard -->
31+
<PropertyGroup Condition="'$(TargetFramework)' == 'netstandard2.1'">
32+
<TargetFrameworkMonikerAssemblyAttributesPath>$([System.IO.Path]::Combine('$(IntermediateOutputPath)','$(TargetFrameworkMoniker).AssemblyAttributes$(DefaultLanguageSourceExtension)'))</TargetFrameworkMonikerAssemblyAttributesPath>
33+
</PropertyGroup>
34+
<ItemGroup>
35+
<EmbeddedFiles Include="$(GeneratedAssemblyInfoFile)"/>
36+
</ItemGroup>
37+
38+
<PropertyGroup Condition="'$(GITHUB_ACTIONS)' == 'true'">
39+
<ContinuousIntegrationBuild>true</ContinuousIntegrationBuild>
2540
</PropertyGroup>
2641

2742
<ItemGroup>
2843
<None Include="..\README.md" Pack="true" PackagePath="\"/>
2944
</ItemGroup>
3045

3146
<ItemGroup>
32-
<PackageReference Include="System.Buffers" Version="4.6.0" />
33-
<PackageReference Include="System.Memory" Version="4.6.0" />
34-
<PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="6.1.0" />
47+
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All"/>
48+
<PackageReference Include="System.Buffers" Version="4.6.0"/>
49+
<PackageReference Include="System.Memory" Version="4.6.0"/>
50+
<PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="6.1.0"/>
3551
</ItemGroup>
3652

3753
</Project>

Miku.Core/NetClient.cs

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -297,18 +297,32 @@ private static void Receive(SocketAsyncEventArgs args)
297297
}
298298
catch (Exception e)
299299
{
300+
client._receivedData.Clear();
300301
client.OnError?.Invoke(e);
301302
goto cont_receive;
302303
}
303304
}
304305

305306
// still the original data or partially the original data
306-
var offset = Unsafe.ByteOffset(ref MemoryMarshal.GetReference(processedData.Span),
307-
ref MemoryMarshal.GetReference(client._receivedData.WrittenSpan));
307+
ref byte processed = ref MemoryMarshal.GetReference(processedData.Span);
308+
ref byte originalData = ref MemoryMarshal.GetReference(client._receivedData.WrittenSpan);
309+
bool original = Unsafe.IsAddressGreaterThan(ref processed, ref originalData) &&
310+
Unsafe.IsAddressLessThan(ref processed,
311+
ref Unsafe.Add(ref originalData, client._receivedData.WrittenCount));
308312
// if offset is less than length of _receivedData.WrittenMemory, then it's the original data
309-
if ((long)offset < client._receivedData.WrittenCount)
313+
if (original)
310314
{
311-
index = (int)offset + processedData.Length;
315+
IntPtr diff = Unsafe.ByteOffset(
316+
ref Unsafe.Add(ref processed, processedData.Length),
317+
ref originalData);
318+
if (diff.ToInt64() > int.MaxValue)
319+
{
320+
client.OnError?.Invoke(new ArithmeticException("diff is too large"));
321+
client._receivedData.Clear();
322+
goto cont_receive;
323+
}
324+
325+
index = diff.ToInt32();
312326
}
313327

314328
// invoke event
@@ -326,7 +340,7 @@ private static void Receive(SocketAsyncEventArgs args)
326340
if (leftOver > 0 && index < client._receivedData.WrittenCount && index > 0)
327341
{
328342
// copy left over data to temp stack memory - faster than array pool
329-
if (leftOver <=1024)
343+
if (leftOver <= 1024)
330344
{
331345
client._receivedData.WrittenSpan.Slice(index).CopyTo(tempStackMem);
332346
client._receivedData.Clear();

0 commit comments

Comments
 (0)