aboutsummaryrefslogtreecommitdiff
path: root/CPP/7zip/Compress/LzfseDecoder.cpp
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--CPP/7zip/Compress/LzfseDecoder.cpp26
1 files changed, 17 insertions, 9 deletions
diff --git a/CPP/7zip/Compress/LzfseDecoder.cpp b/CPP/7zip/Compress/LzfseDecoder.cpp
index 236d5bd..b224a33 100644
--- a/CPP/7zip/Compress/LzfseDecoder.cpp
+++ b/CPP/7zip/Compress/LzfseDecoder.cpp
@@ -80,7 +80,7 @@ HRESULT CDecoder::DecodeUncompressed(UInt32 unpackSize)
80 UInt32 cur = unpackSize; 80 UInt32 cur = unpackSize;
81 if (cur > kBufSize) 81 if (cur > kBufSize)
82 cur = kBufSize; 82 cur = kBufSize;
83 UInt32 cur2 = (UInt32)m_InStream.ReadBytes(buf, cur); 83 const UInt32 cur2 = (UInt32)m_InStream.ReadBytes(buf, cur);
84 m_OutWindowStream.PutBytes(buf, cur2); 84 m_OutWindowStream.PutBytes(buf, cur2);
85 if (cur != cur2) 85 if (cur != cur2)
86 return S_FALSE; 86 return S_FALSE;
@@ -91,7 +91,7 @@ HRESULT CDecoder::DecodeUncompressed(UInt32 unpackSize)
91 91
92HRESULT CDecoder::DecodeLzvn(UInt32 unpackSize, UInt32 packSize) 92HRESULT CDecoder::DecodeLzvn(UInt32 unpackSize, UInt32 packSize)
93{ 93{
94 PRF(printf("\nLZVN %7u %7u", unpackSize, packSize)); 94 PRF(printf("\nLZVN 0x%07x 0x%07x\n", unpackSize, packSize));
95 95
96 UInt32 D = 0; 96 UInt32 D = 0;
97 97
@@ -241,19 +241,27 @@ HRESULT CDecoder::DecodeLzvn(UInt32 unpackSize, UInt32 packSize)
241 return S_FALSE; 241 return S_FALSE;
242 242
243 // LZVN encoder writes 7 additional zero bytes 243 // LZVN encoder writes 7 additional zero bytes
244 if (packSize != 7) 244 if (packSize < 7)
245 return S_FALSE; 245 return S_FALSE;
246 do 246 for (unsigned i = 0; i < 7; i++)
247 { 247 {
248 Byte b; 248 Byte b;
249 if (!m_InStream.ReadByte(b)) 249 if (!m_InStream.ReadByte(b))
250 return S_FALSE; 250 return S_FALSE;
251 packSize--;
252 if (b != 0) 251 if (b != 0)
253 return S_FALSE; 252 return S_FALSE;
254 } 253 }
255 while (packSize != 0); 254 packSize -= 7;
256 255 if (packSize)
256 {
257 PRF(printf("packSize after unused = %u\n", packSize));
258 // if (packSize <= 0x100) { Byte buf[0x100]; m_InStream.ReadBytes(buf, packSize); }
259 /* Lzvn block that is used in HFS can contain junk data
260 (at least 256 bytes) after payload data. Why?
261 We ignore that junk data, if it's HFS (LzvnMode) mode. */
262 if (!LzvnMode)
263 return S_FALSE;
264 }
257 return S_OK; 265 return S_OK;
258} 266}
259 267
@@ -479,7 +487,7 @@ static Z7_FORCE_INLINE int FseInStream_Init(CBitStream *s,
479static Z7_FORCE_INLINE UInt32 BitStream_Pull(CBitStream *s, unsigned numBits) 487static Z7_FORCE_INLINE UInt32 BitStream_Pull(CBitStream *s, unsigned numBits)
480{ 488{
481 s->numBits -= numBits; 489 s->numBits -= numBits;
482 UInt32 v = s->accum >> s->numBits; 490 const UInt32 v = s->accum >> s->numBits;
483 s->accum = mask31(s->accum, s->numBits); 491 s->accum = mask31(s->accum, s->numBits);
484 return v; 492 return v;
485} 493}
@@ -922,7 +930,7 @@ HRESULT CDecoder::CodeReal(ISequentialInStream *inStream, ISequentialOutStream *
922 coderReleaser.NeedFlush = false; 930 coderReleaser.NeedFlush = false;
923 HRESULT res = m_OutWindowStream.Flush(); 931 HRESULT res = m_OutWindowStream.Flush();
924 if (res == S_OK) 932 if (res == S_OK)
925 if ((inSize && *inSize != m_InStream.GetProcessedSize()) 933 if ((!LzvnMode && inSize && *inSize != m_InStream.GetProcessedSize())
926 || (outSize && *outSize != m_OutWindowStream.GetProcessedSize())) 934 || (outSize && *outSize != m_OutWindowStream.GetProcessedSize()))
927 res = S_FALSE; 935 res = S_FALSE;
928 return res; 936 return res;