Sparkle: HTTP_REQUEST_V2.RequestInfoCount is read 4 bytes too late on Win64, so http.sys request info (authentication) is never seen

Product and environment

  • TMS Sparkle 3.41 (Sparkle.HttpSys.Api.pas)
  • Delphi 12 Athens (Studio 23.0)
  • Platform: Win64. Win32 is not affected.
  • Seen on Windows Server (domain-joined, HTTPS) and reproduced on Windows 11 (HTTP, localhost).

Summary

HTTP_REQUEST_V2 in Sparkle.HttpSys.Api.pas declares a padding field Dummy1: DWORD between pSslInfo and RequestInfoCount:

  HTTP_REQUEST_V2 = record
    ...
    RawConnectionId: HTTP_RAW_CONNECTION_ID;
    pSslInfo: PHTTP_SSL_INFO;
    Dummy1: DWORD;                      // <-- correct on Win32, wrong on Win64
    RequestInfoCount: USHORT;
    pRequestInfo: PHTTP_REQUEST_INFO;
  end;

The padding is right for Win32 and wrong for Win64. On Win64, RequestInfoCount therefore reads 2 bytes of padding and is always 0. Any code that walks pRequestInfo, such as reading the HttpRequestInfoTypeAuth entry after enabling kernel-mode authentication, finds no entries. Every request then looks unauthenticated, even though http.sys completed the Negotiate (Kerberos or NTLM) handshake.

Why

In http.h, HTTP_REQUEST_V2 embeds HTTP_REQUEST_V1 as a struct and then adds RequestInfoCount and pRequestInfo. So the V2 fields begin after V1 rounded up to V1's alignment, which is 8 because V1 contains ULONGLONG fields.

V1 ends (after pSslInfo) V1 padded to 8 RequestInfoCount pRequestInfo Sparkle's RequestInfoCount
Win32 460 464 464 468 464 (correct: Dummy1 happens to equal the padding)
Win64 848 848 848 856 852 (wrong: lands in the padding before pRequestInfo)

pRequestInfo happens to come out at the right offset on Win64 (856), because the pointer realigns to 8. Only the count is wrong. Since it reads 0, nothing is ever iterated.

Steps to reproduce

  1. Create a THttpSysServer and enable Negotiate on its URL group before the queue starts. For example, override BeforeStart, call Session.Start, and then:

    FillChar(AuthInfo, SizeOf(AuthInfo), 0);
    AuthInfo.Flags := HTTP_PROPERTY_FLAG_PRESENT;
    AuthInfo.AuthSchemes := HTTP_AUTH_ENABLE_NEGOTIATE;
    HttpCheck(HttpSetUrlGroupProperty(Session.UrlGroupID,
      HttpServerAuthenticationProperty, @AuthInfo, SizeOf(AuthInfo)));
    
    
  2. In a module, read THttpSysContext(Context).SysRequest.RawRequest^.RequestInfoCount and walk pRequestInfo looking for HttpRequestInfoTypeAuth. Answer 401 with WWW-Authenticate: Negotiate if no successful auth entry is found.

  3. Build Win32, run it, and call it with Windows credentials: curl.exe --negotiate -u : http://localhost:<port>/ (use C:\Windows\System32\curl.exe)

    • RequestInfoCount is 6 on Windows 11, with the auth entry first.
    • Authentication succeeds and the access token is present.
  4. Build the same code as Win64 and repeat.

    • RequestInfoCount is always 0, including on the request that carries the completed Negotiate token.
    • Every request is refused.

netsh http show servicestate view=requestq verbose=yes confirms the URL group has "Authentication schemes enabled: Negotiate", so http.sys is configured correctly. The request info is there; it is just read at the wrong offset.

Suggested fix

Make the padding Win32-only, or declare V2 so the compiler pads V1 the way C does. For example:

    pSslInfo: PHTTP_SSL_INFO;
{$IFDEF CPUX86}
    Dummy1: DWORD;  // V1 is embedded as a struct in http.h: pad it to 8
{$ENDIF}
    RequestInfoCount: USHORT;
    pRequestInfo: PHTTP_REQUEST_INFO;

A regression check is cheap. Assert the offsets on each platform:

  • NativeUInt(@PHTTP_REQUEST_V2(nil).RequestInfoCount) is 464 on Win32 and 848 on Win64;
  • NativeUInt(@PHTTP_REQUEST_V2(nil).pRequestInfo) is 468 on Win32 and 856 on Win64.

Possibly related (not verified)

Sparkle's enum types inside these records (HTTP_VERB, HTTP_REQUEST_INFO_TYPE, HTTP_AUTH_STATUS, HTTP_REQUEST_AUTH_TYPE) appear to use Delphi's default 1-byte enum size, where the C enums are 4 bytes. Where the next field is a pointer or a 4-byte value, alignment hides the difference. But UnknownVerbLength and RawUrlLength, the two USHORTs after Verb, would sit at offsets 38 and 40 instead of 40 and 42 on both platforms. {$MINENUMSIZE 4} in the unit would rule this out.

Our workaround

We don't patch Sparkle. Our code reads RequestInfoCount and pRequestInfo at offsets it computes itself: the offset of pSslInfo, plus the pointer size, rounded up to 8, then the count, then the pointer, pointer-aligned.

Thank you for the report. We confirmed the issue and the fix will be included in next release.