diff --git a/components/fpspreadsheet/fpsstrings.pas b/components/fpspreadsheet/fpsstrings.pas index bd43da88d..ac3e9bffe 100644 --- a/components/fpspreadsheet/fpsstrings.pas +++ b/components/fpspreadsheet/fpsstrings.pas @@ -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 '+ diff --git a/components/fpspreadsheet/xlsbiff8.pas b/components/fpspreadsheet/xlsbiff8.pas index bef12eb0e..f95ec9d83 100755 --- a/components/fpspreadsheet/xlsbiff8.pas +++ b/components/fpspreadsheet/xlsbiff8.pas @@ -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;