sc/source/ui/unoobj/exceldetect.cxx | 18 +++++++++++--- sc/source/ui/unoobj/scdetect.cxx | 45 ++++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+), 4 deletions(-)
New commits: commit b46688a663b8709e0e0795f25ef8961db1f46cba Author: Kohei Yoshida <kohei.yosh...@gmail.com> Date: Sat Jul 27 20:00:51 2013 -0400 fdo#64423: Detect BIFF 2 (and 3) file format like we should. Change-Id: I1421cca4b0ef8e9410aab5725cc5a8d9cffef7a9 diff --git a/sc/source/ui/unoobj/exceldetect.cxx b/sc/source/ui/unoobj/exceldetect.cxx index db040e3..fb15a3c 100644 --- a/sc/source/ui/unoobj/exceldetect.cxx +++ b/sc/source/ui/unoobj/exceldetect.cxx @@ -74,6 +74,10 @@ bool hasStream(const uno::Reference<io::XInputStream>& xInStream, const OUString return xStorage->IsStream(rName); } +/** + * We detect BIFF 2, 3 and 4 file types together since the only thing that + * set them apart is the BOF ID. + */ bool isExcel40(const uno::Reference<io::XInputStream>& xInStream) { SfxMedium aMedium; @@ -93,12 +97,18 @@ bool isExcel40(const uno::Reference<io::XInputStream>& xInStream) sal_uInt16 nBofId, nBofSize; *pStream >> nBofId >> nBofSize; - if (nBofId != 0x0409) - // This ID signifies Excel 4.0 format. It must be 0x0409. - return false; + switch (nBofId) + { + case 0x0009: // Excel 2.1 worksheet (BIFF 2) + case 0x0209: // Excel 3.0 worksheet (BIFF 3) + case 0x0409: // Excel 4.0 worksheet (BIFF 4) + break; + default: + return false; + } if (nBofSize < 4 || 16 < nBofSize) - // BOF record must be sized between 4 and 16 for Excel 4.0 stream. + // BOF record must be sized between 4 and 16 for BIFF 2, 3 and 4. return false; sal_Size nPos = pStream->Tell(); diff --git a/sc/source/ui/unoobj/scdetect.cxx b/sc/source/ui/unoobj/scdetect.cxx index ce43086..be11ace 100644 --- a/sc/source/ui/unoobj/scdetect.cxx +++ b/sc/source/ui/unoobj/scdetect.cxx @@ -71,6 +71,48 @@ using namespace ::com::sun::star::beans; using namespace ::com::sun::star::lang; using namespace ::com::sun::star::ucb; +#include <stdio.h> +#include <string> +#include <sys/time.h> + +namespace { + +class stack_printer +{ +public: + explicit stack_printer(const char* msg) : + msMsg(msg) + { + fprintf(stdout, "%s: --begin\n", msMsg.c_str()); + mfStartTime = getTime(); + } + + ~stack_printer() + { + double fEndTime = getTime(); + fprintf(stdout, "%s: --end (duration: %g sec)\n", msMsg.c_str(), (fEndTime - mfStartTime)); + } + + void printTime(int line) const + { + double fEndTime = getTime(); + fprintf(stdout, "%s: --(%d) (duration: %g sec)\n", msMsg.c_str(), line, (fEndTime - mfStartTime)); + } + +private: + double getTime() const + { + timeval tv; + gettimeofday(&tv, NULL); + return tv.tv_sec + tv.tv_usec / 1000000.0; + } + + ::std::string msMsg; + double mfStartTime; +}; + +} + ScFilterDetect::ScFilterDetect( const uno::Reference<uno::XComponentContext>& /*xContext*/ ) { } @@ -217,6 +259,7 @@ static sal_Bool lcl_MayBeDBase( SvStream& rStream ) OUString SAL_CALL ScFilterDetect::detect( uno::Sequence<beans::PropertyValue>& lDescriptor ) throw( uno::RuntimeException ) { + stack_printer __stack_printer__("ScFilterDetect::detect"); uno::Reference< XInputStream > xStream; uno::Reference< XContent > xContent; uno::Reference< XInteractionHandler > xInteraction; @@ -296,6 +339,8 @@ OUString SAL_CALL ScFilterDetect::detect( uno::Sequence<beans::PropertyValue>& l bDeepDetection = lDescriptor[nProperty].Value.get<sal_Bool>(); } + fprintf(stdout, "ScFilterDetect::detect: type = '%s'\n", rtl::OUStringToOString(aTypeName, RTL_TEXTENCODING_UTF8).getStr()); + // can't check the type for external filters, so set the "dont" flag accordingly SolarMutexGuard aGuard; //SfxFilterFlags nMust = SFX_FILTER_IMPORT, nDont = SFX_FILTER_NOTINSTALLED; _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits