From 6aedb395f4691294d3809f8f84d6539885a31627 Mon Sep 17 00:00:00 2001 From: wp_xxyyzz Date: Mon, 26 Feb 2018 22:20:06 +0000 Subject: [PATCH] fpspreadsheet: Fix xls reader crashing if comment has record sequence OBJ-CONTINUE-TX0-CONTINUE instead of OBJ-TX0-CONTINUE. git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@6214 8e941d3f-bd1b-0410-a28a-d453659cc2b4 --- components/fpspreadsheet/source/common/xlsbiff8.pas | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/components/fpspreadsheet/source/common/xlsbiff8.pas b/components/fpspreadsheet/source/common/xlsbiff8.pas index ea5a70fb7..f7e5f2a83 100644 --- a/components/fpspreadsheet/source/common/xlsbiff8.pas +++ b/components/fpspreadsheet/source/common/xlsbiff8.pas @@ -537,7 +537,7 @@ var comment: TBIFF8Comment; rtParams: TsRichTextParams; begin - if FCommentPending then begin + if FCommentPending and (FCommentLen > 0) then begin commentStr := Utf8Encode(ReadWideString(AStream, FCommentLen, rtParams)); if commentStr <> '' then begin @@ -605,6 +605,7 @@ begin if objType = $19 then begin // $19 = object is a "comment" FCommentPending := true; FCommentID := objID; + FCommentLen := 0; // will be determined in following TX0 record exit; end else FCommentPending := false; @@ -886,6 +887,9 @@ begin RecordSize := WordLEToN(AStream.ReadWord); PendingRecordSize := RecordSize; +// For debugging to find out in which record a crash happens: +// WriteLn(Format('Stream.Pos: %d, RecordType: $%.04x, RecordSize: %d', [AStream.Position-4, RecordType, RecordSize])); + CurStreamPos := AStream.Position; case RecordType of