From e9c50fbbc3b07ef927d133da9cf2395c55611e0f Mon Sep 17 00:00:00 2001 From: offtkp Date: Sat, 2 Apr 2022 15:49:32 +0300 Subject: tdf#103954: Z compressed graphic formats support for EMF/WMF MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Added .emz and .wmz file opening support - Added a function to check for Z compression that all z comp. formats can use - Added 3 unit tests for emf/emz/wmz files and the example files have been checked with a different tool (File Viewer 4) - emf/emz file detection changed from magic byte checking to extension checking, like wmf/wmz does Change-Id: I3e433fd23d18482648a51cd04b8f467368e97b62 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/132456 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl --- tools/source/zcodec/zcodec.cxx | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) (limited to 'tools') diff --git a/tools/source/zcodec/zcodec.cxx b/tools/source/zcodec/zcodec.cxx index 97a03a463021..80daa1507a19 100644 --- a/tools/source/zcodec/zcodec.cxx +++ b/tools/source/zcodec/zcodec.cxx @@ -36,7 +36,7 @@ #define GZ_COMMENT 0x10 /* bit 4 set: file comment present */ #define GZ_RESERVED 0xE0 /* bits 5..7: reserved */ -const int gz_magic[2] = { 0x1f, 0x8b }; /* gzip magic header */ +constexpr sal_uInt16 GZ_MAGIC_BYTES_LE = 0x8B1F; /* gzip magic bytes, little endian */ ZCodec::ZCodec( size_t nInBufSize, size_t nOutBufSize ) : meState(STATE_INIT) @@ -58,6 +58,16 @@ ZCodec::~ZCodec() delete pStream; } +bool ZCodec::IsZCompressed( SvStream& rIStm ) +{ + sal_uInt64 nCurPos = rIStm.Tell(); + rIStm.Seek( 0 ); + sal_uInt16 nFirstTwoBytes = 0; + rIStm.ReadUInt16( nFirstTwoBytes ); + rIStm.Seek( nCurPos ); + return nFirstTwoBytes == GZ_MAGIC_BYTES_LE; +} + void ZCodec::BeginCompression( int nCompressLevel, bool gzLib ) { assert(meState == STATE_INIT); @@ -272,12 +282,11 @@ void ZCodec::InitDecompress(SvStream & inStream) if ( mbStatus && mbGzLib ) { sal_uInt8 j, nMethod, nFlags; - for (int i : gz_magic) // gz - magic number - { - inStream.ReadUChar( j ); - if ( j != i ) - mbStatus = false; - } + sal_uInt16 nFirstTwoBytes; + inStream.Seek( 0 ); + inStream.ReadUInt16( nFirstTwoBytes ); + if ( nFirstTwoBytes != GZ_MAGIC_BYTES_LE ) + mbStatus = false; inStream.ReadUChar( nMethod ); inStream.ReadUChar( nFlags ); if ( nMethod != Z_DEFLATED ) -- cgit