delphidabbler / codesnip

A code bank designed with Pascal in mind
https://delphidabbler.com/software/codesnip
Other
110 stars 33 forks source link

Potential out-of-range or memory access error in `UEncodings` unit #97

Closed delphidabbler closed 1 year ago

delphidabbler commented 1 year ago

In WideCharToChar in UEncodings the 1st call to WideCharToMultiByte passes reference to Dest array, before that array's size has been set. Instead of passing Dest, nil should be passed here.

Instead of

  BufSize := WideCharToMultiByte(
    CodePage, 0, @Source, 1, @Dest[0], 0, nil, nil
  );

uses

  BufSize := WideCharToMultiByte(
    CodePage, 0, @Source, 1, nil, 0, nil, nil
  );
delphidabbler commented 1 year ago

Noticed this in caboli branch where Delphi 11.3 threw a range error in this routine. Already applied the fix there.

delphidabbler commented 1 year ago

Fixed at commit e43816c6007ac3eed30d5e400f4889f278976218