Skip to content

Code audit fix: BSDIFF overflow, Zip path traversal, process lifecycle, event systemΒ #514

Description

@JusterZhu

Code Audit β€” Critical/High Bug Fixes

Based on a full code audit of GeneralUpdate.Core and GeneralUpdate.Differential, this PR fixes ~25 bugs across the Core and Differential libraries.

πŸ”΄ Critical

Bug File Description
WriteInt64 overflow BsdiffDiffer.cs:691 -long.MinValue overflows, corrupting BSDIFF sign-magnitude encoding
(int)control[0] truncation BsdiffDiffer.cs:386,396,428 long > int.MaxValue silently truncated to negative β€” data loss on large patches
ReadFileWithBudget silent truncation StreamingHdiffDiffer.cs:436-454 Files > 128MB silently truncated, producing incorrect patches
Zip decompress path traversal ZipCompressionStrategy.cs:140-160 No validation β€” malicious ../../evil.exe entries can escape extraction dir
Overly broad StartsWith match ZipCompressionStrategy.cs:51,85 "foo.dll" matches "foobar.dll" β€” wrong entries deleted in existing zip

🟠 High

Bug File Description
ProcessExit deadlock ClientStrategy.cs:776 GetAwaiter().GetResult() in AppDomain.ProcessExit handler can deadlock with WPF/WinForms sync ctx
Strategy unconditional suicide WindowsStrategy.cs, LinuxStrategy.cs, MacStrategy.cs finally kills updater even when app launch failed β€” no recovery possible
Trace.Listeners global pollution GeneralTracer.cs:158 Dispose() calls Trace.Listeners.Clear() β€” kills other libraries trace output
ProcessContract null check order ProcessContract.cs:186-188 Directory.Exists(null) before null check β€” misleading error message
HubConnection dispose lifecycle UpgradeHubService.cs:49-88 DisposeAsync doesnt null _connection β€” StartAsync after dispose throws NRE
ConfigurationMapper silent null ConfigurationMapper.cs:80 null source returns empty config β€” caller unaware of misconfiguration
DefaultRetryPolicy status code match DefaultRetryPolicy.cs:134-138 s.Contains("500") can match URL paths, not just status codes

🟑 Medium

Bug File Description
EventManager singleton not resettable EventManager.cs Added Reset() static method

Files Changed

  • GeneralUpdate.Differential/Differ/BsdiffDiffer.cs
  • GeneralUpdate.Differential/Differ/StreamingHdiffDiffer.cs
  • GeneralUpdate.Core/Compress/ZipCompressionStrategy.cs
  • GeneralUpdate.Core/Strategy/ClientStrategy.cs
  • GeneralUpdate.Core/Strategy/WindowsStrategy.cs
  • GeneralUpdate.Core/Strategy/LinuxStrategy.cs
  • GeneralUpdate.Core/Strategy/MacStrategy.cs
  • GeneralUpdate.Core/Tracer/GeneralTracer.cs
  • GeneralUpdate.Core/Configuration/ProcessContract.cs
  • GeneralUpdate.Core/Configuration/ConfigurationMapper.cs
  • GeneralUpdate.Core/Hubs/UpgradeHubService.cs
  • GeneralUpdate.Core/Download/Policy/DefaultRetryPolicy.cs
  • GeneralUpdate.Core/Event/EventManager.cs

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions