diff --git a/packages/chm/src/chmfiftimain.pas b/packages/chm/src/chmfiftimain.pas index 6510e30720..2fee065851 100644 --- a/packages/chm/src/chmfiftimain.pas +++ b/packages/chm/src/chmfiftimain.pas @@ -821,7 +821,8 @@ begin if CopyLastWordCharCount > 0 then Result := Copy(ALastWord, 1, CopyLastWordCharCount); SetLength(Result, (WordLength-1) + CopyLastWordCharCount); - FStream.Read(Result[1+CopyLastWordCharCount], WordLength-1); + if WordLength > 1 then + FStream.Read(Result[1+CopyLastWordCharCount], WordLength-1); end; function TChmSearchReader.ReadIndexNodeEntry (ALastWord: String; out AWord: String; out diff --git a/packages/chm/src/chmreader.pas b/packages/chm/src/chmreader.pas index fc59ca1ac3..b65f557caf 100644 --- a/packages/chm/src/chmreader.pas +++ b/packages/chm/src/chmreader.pas @@ -277,7 +277,7 @@ procedure TChmReader.ReadCommonData; repeat Stream.Read(buf, 50); Result := Result + buf; - until Pos(#0, buf) > -1; + until IndexByte(buf, 50, 0) <> -1; if FixURL then Result := StringReplace(Result, '\', '/', [rfReplaceAll]); end;