fpspreadsheet: Prevent biff8 reader crashing for a special file containing comboboxes (see forum http://forum.lazarus.freepascal.org/index.php/topic,29409.0.html).

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@4276 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2015-08-20 13:00:38 +00:00
parent 4ffb9185c2
commit 7fd6590a6b
2 changed files with 11 additions and 2 deletions

View File

@ -43,6 +43,7 @@ resourcestring
rsWorksheetNotFound1 = 'Worksheet not found.';
rsInvalidWorksheetName = '"%s" is not a valid worksheet name.';
rsDefectiveInternalStructure = 'Defective internal structure of %s file.';
rsFileStructureError = 'File structure error in %s record, position %d.';
rsUnknownDataType = 'Unknown data type.';
rsUnknownErrorType = 'Unknown error type.';
rsTruncateTooLongCellText = 'Text value exceeds %d character limit in cell %s '+

View File

@ -521,11 +521,13 @@ end;
procedure TsSpreadBIFF8Reader.ReadOBJ(const AStream: TStream);
var
subrecID, subrecSize: Word;
streamPos: Int64;
streamPos, p: Int64;
streamSize: Int64;
lastSubRec: Boolean;
objType: Word;
objID: Word;
begin
streamSize := AStream.Size;
lastSubRec := false;
while not lastSubRec do begin
subrecID := WordLEToN(AStream.ReadWord);
@ -546,7 +548,13 @@ begin
INT_EXCEL_OBJID_FTEND:
lastSubRec := true;
end;
AStream.Position := streamPos + subrecSize;
p := streamPos + subrecSize;
if p < streamSize then
AStream.Position := p
else begin
FWorkbook.AddErrorMsg(Format(rsFileStructureError, ['OBJ', streamPos]));
exit;
end;
end;
end;