From a624b7f6717dcd9a981b7b1b9f9ecc5c2bdf9716 Mon Sep 17 00:00:00 2001 From: joshy Date: Tue, 2 Jul 2013 15:07:43 +0000 Subject: [PATCH] Handle ID_CONTINUE inside some tags. git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@2757 8e941d3f-bd1b-0410-a28a-d453659cc2b4 --- components/fpspreadsheet/xlsbiff8.pas | 36 ++++++++++++++++++++++----- 1 file changed, 30 insertions(+), 6 deletions(-) diff --git a/components/fpspreadsheet/xlsbiff8.pas b/components/fpspreadsheet/xlsbiff8.pas index e2b41d58b..2820f46cd 100755 --- a/components/fpspreadsheet/xlsbiff8.pas +++ b/components/fpspreadsheet/xlsbiff8.pas @@ -1385,6 +1385,9 @@ var i: Integer; j: SizeUInt; lLen: SizeInt; + RecordType: WORD; + RecordSize: WORD; + C: char; begin StringFlags:=AStream.ReadByte; Dec(PendingRecordSize); @@ -1412,22 +1415,43 @@ begin Result:=WideStringLEToN(Result); end else begin //String is 1 byte per char, this is UTF-16 with the high byte ommited because it is zero - // so decompress and then convert - if ALength > PendingRecordSize then lLen := PendingRecordSize - else lLen := ALength; - + //so decompress and then convert + lLen:=ALength; SetLength(DecomprStrValue, lLen); for i := 1 to lLen do begin - DecomprStrValue[i] := WideChar(AStream.ReadByte()); + C:=WideChar(AStream.ReadByte()); + DecomprStrValue[i] := C; + Dec(PendingRecordSize); + if (PendingRecordSize<=0) and (iINT_EXCEL_ID_CONTINUE then begin + Raise Exception.Create('[TsSpreadBIFF8Reader.ReadWideString] Expected CONTINUE record not found.'); + end else begin + PendingRecordSize:=RecordSize; + DecomprStrValue:=copy(DecomprStrValue,1,i)+ReadWideString(AStream,ALength-i); + break; + end; + end; end; - Dec(PendingRecordSize, lLen); Result := DecomprStrValue; end; if StringFlags and 8 = 8 then begin //Rich string (This only happend in BIFF8) for j := 1 to RunsCounter do begin + if (PendingRecordSize<=0) then begin + //A CONTINUE may happend here + RecordType := WordLEToN(AStream.ReadWord); + RecordSize := WordLEToN(AStream.ReadWord); + if RecordType<>INT_EXCEL_ID_CONTINUE then begin + Raise Exception.Create('[TsSpreadBIFF8Reader.ReadWideString] Expected CONTINUE record not found.'); + end else begin + PendingRecordSize:=RecordSize; + end; + end; AStream.ReadWord; AStream.ReadWord; dec(PendingRecordSize,2*2);