summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
Diffstat (limited to 'tools')
-rw-r--r--tools/source/zcodec/zcodec.cxx23
1 files changed, 16 insertions, 7 deletions
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 )