TROWinInetHTTPChannel reads out of HTTPQueryInfo response wrong

In Delphi 11.2 (and all Unicode Delphi versions), the function ReceiveData uses WinApi Function HTTPQueryInfo, which calls the WideString variant HTTPQueryInfoW.
The 4th parameter of HTTPQueryInfoW “amount of written bytes” is the same as for HTTPQueryInfoA. Your code uses this Size to set Length of string, in Unicode Delphi of UnicodeString. Which results in partially random strings, with a lots of broken letters.

IndyComponents use {$IFDEF UNICODE} div 2{$ENDIF}) on same spot.

Example:

...
if (l_status >= 300) and (l_status <> HTTP_500_code) then begin
    l_index := 0;
    l_size := const_MaxStatusText;
    SetLength(l_statusText, l_size);
    if HTTPQueryInfo(aRequest, HTTP_QUERY_STATUS_TEXT, @l_statusText[1], l_size, l_index) then begin
      SetLength(l_statusText, l_size  {$IFDEF FIX_IT} div SizeOf(Char) {$ENDIF});
      raise EROWinInetHttpException.CreateFmt('%s (%d)', [l_statusText, l_status], GetLastError);
    end;
  end;

Logged as bugs://D19351.

bugs://D19351 was closed as fixed.

Thank you for implementing the fix very quickly.
Which version would contain these changes? We are planning on updating to the newest version soon.

Hi,

this fix will be included into .1563.
as a temporary workaround, you can use your fix

1 Like

Hi,

we released beta (.1561) with this fix