#1 2025-01-29 21:24:38

rpa
Member
Registered: 2025-01-29
Posts: 1

Bug when hashing long unicode strings

With certain long keys the following code throws AV

  s := StringOfChar('x', 222);
  dict := Collections.NewKeyValue<string,integer>;
  dict.TryGetValue(s, v);

Debugging it it looks like that the HashSynUnicode code is missing a defererence here:

    if l > 255 then // no need to hash too big a content
    begin
      Item := @PAnsiChar(Item)[l - 256]; // hash ending of string
      l := 256;
    end;

It should be PAnsiChar(Item^), the current code hashes the memory at an offset relative to the string reference, not the start of the string content (with strings longer than 127 chars).

Offline

#2 2025-01-30 08:15:48

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,845
Website

Re: Bug when hashing long unicode strings

Should be fixed by
https://github.com/synopse/mORMot2/commit/e625f9224

I have added some dedicated tests in
https://github.com/synopse/mORMot2/commit/d2ee299a7

Thanks a lot for the report and investigation!

Offline

Board footer

Powered by FluxBB